URLEncodedFormat example

Following is an example to show the usage of the function "URLEncodedFormat".

Description: Generates an URL-encoded string. For example, it replaces spaces with %20, and non-alphanumeric characters with equivalent hexadecimal escape sequences.

Returns: A copy of a string, URL-encoded.

syntax: URLEncodedFormat(string [, charset ])

string: A string or a variable that contains a string.

charset: The character encoding in which the string is encoded. Optional.

The following list includes commonly used values:

* utf-8 * iso-8859-1 * windows-1252 * us-ascii * shift_jis * iso-2022-jp * euc-jp * euc-kr * big5 * euc-cn * utf-16

Here is a simple example:

<cfset enc = URLEncodedFormat("Adobe Cold Fusion 8")>
<br><cfoutput>The URLEncodedFormat of "Adobe Cold Fusion 8" is <br>"#enc#".
</cfoutput>

<br><cfset enc = URLEncodedFormat("JRUN&ColdFusion 8.0.1")>
<cfoutput>The URLEncodedFormat of "JRUN&ColdFusion 8.0.1" is <br>"#enc#".
</cfoutput>

Another example follows:

<h3>URLEncodedFormat Example</h3>
<cfif IsDefined("url.myExample")>
<p>The url variable url.myExample was passed from the previous link ...
its value is:
<br><b>"<cfoutput>#url.myExample#</cfoutput>"</b>
</cfif>
<p>This function returns a URL encoded string.
<cfset s = "My url-encoded string has special characters & other stuff">
<p> <A HREF = "urlencodedformat.cfm?myExample=<cfoutput>#URLEncodedFormat(s)#
</cfoutput>"
>Click me</A>

You can download the code using the download button.

Comments
# Posted By sdgsdu | 10/10/08 3:19 AM
# Posted By sdgsdoo | 10/10/08 3:23 AM
# Posted By xcvxcb | 10/10/08 3:29 AM
# Posted By sdgsdi | 10/10/08 3:32 AM
# Posted By asgfas | 10/10/08 3:36 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner