URLEncode

Description

Applies URL encoding rules to a string.

Applies to

PSServerClass object

Syntax

psServer.URLEncode( string )

Argument

Description

string

The string to which you want to apply URL encoding

Returns

String

Usage

At runtime, URLEncode has the following behavior:

Application server

Runtime behavior

ASP

Calls the URLEncode method of the Server object

JSP

Calls the encode method of java.net.URLEncoder

Examples

Example 1

The following example applies URL encoding to a URL query string that contains a percent sign. This string needs to be encoded because the percent sign is itself used to indicate URL-encoded characters:

value1 = psServer.URLEncode("33%");
value2 = psServer.URLEncode("50%");
value3 = psServer.URLEncode("100%");
text = "<P>Increase salary by:</P>";
text += "<A HREF='" + "salary.asp?increase=" + value1 +
		"'> 33% </A> <BR>";
text += "<A HREF='" + "salary.asp?increase=" + value2 +
		"'> 50% </A> <BR>";
text += "<A HREF='" + "salary.asp?increase=" + value3 +
		"'> 100% </A>";

psDocument.Write(text);

This code sends the following HTML to the browser:

<P>Increase salary by:</P>
<A HREF="salary.asp?increase=33%25")%>"> 33% </A> <BR>
<A HREF="salary.asp?increase=50%25")%>"> 50% </A> <BR>
<A HREF="salary.asp?increase=100%25")%>"> 100% </A>

In the HTML output shown above, the number 25 is the ANSI code for the percent character. The percent sign indicates that the value that follows (in this case, 25) is a URL-encoded character.