URLEncodedFormat(string)

Description

Returns a URL-encoded string. Spaces are replaced with %20, and nonalphanumeric characters with equivalent hexadecimal escape sequences. The function lets you pass arbitrary strings within a URL, because ColdFusion automatically decodes URL parameters that are passed to the template.

Category

Other functions

See also

URLDecode

Parameters

Parameter
Description
string
String to URL encode

Usage

URL encoding is a data format in which high ASCII and nonalphanumeric characters are encoded with a percent sign followed by the two character hexadecimal representation of the character code. For example, a character with code 129 is encoded as %81. Spaces can be encoded as %20.

Query strings in HTTP are always URL-encoded.

URL-encoded strings can be created with the URLEncodedFormat function.

Example

<!--- This example shows URLEncodedFormat --->
<html>
<head>
<title>URLEncodedFormat Example</title>
</head>
<body bgcolor = silver>
<H3>URLEncodedFormat Example</H3>
<cfif IsDefined("url.myExample")>
<P>The url variable url.myExample has been passed from the
previous link ... its value is:
<BR>"<cfoutput>#url.myExample#</cfoutput>"
</cfif>
<P>This function returns a URL encoded string, making it 
safe to pass strings through a URL.
<cfset s = 
  "My url-encoded string has special characters & other stuff">
<P>
<A HREF = 
  "urlencodedformat.cfm?myExample = <cfoutput>#URLEncodedFormat(s)#
</cfoutput>">Click me</A>
</body>
</html>