URLDecode(urlEncodedString)
| Parameter |
Description |
|---|---|
| urlEncodedString |
A string that has been URL-encoded. |
URL encoding is a data format in which high ASCII and nonalphanumeric characters are encoded using 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 using the plus sign (+).
Query strings in HTTP are always URL-encoded.
URL-encoded strings can be created with the URLEncodedFormat function.
Here is an example of the URLDecode and URLEncodedFormat functions. In the example, a string that contains all ASCII character codes in the range 1-255 is created, encoded and decoded. The decoded value is compared with the original string to demonstrate their equality.
<cfscript>
// Build string
s = "";
for (c = 1; c lte 256; c = c + 1)
{
s = s & chr(c);
}
// Encode string and display result
enc = URLEncodedFormat(s);
writeOutput("Encoded string is: '#enc#'.<BR>");
// Decode and compare result with original
dec = URLDecode(enc);
if (dec neq s)
{
writeOutput("Decoded is not the same as encoded.");
}
else
{
writeOutput("All's well on the Western front.");
}
</cfscript>