UrlEncode

Performs percent-encoding on a URL.

These characters have reserved uses in URLs: ! # $ & ' ( ) * + , / : ; = ? @ [ ]. Reserved characters serve a specific purpose in the context of a URL, so they must be encoded when they’re included in a URL for another purpose. For example, the question mark (?) character is used to separate the base URL from a query string. If the text that’s specified within the query string includes a question mark character, that character must be encoded.

This function performs character encoding. It doesn’t encrypt the query parameters in the URL. To encrypt values in a query string for use in CloudPages, use the AMPscript CloudPagesURL() function.

Note

Syntax 

UrlEncode(1, 2)

Properties 

OrdinalTypeDescription
1StringRequired. The URL to encode. The specified value must be a complete URL in order to be percent-encoded.
2BooleanSpecifies the extent of the encoding. If the value is true, all reserved characters in the URL are converted to percent-encoded values, except for space characters, which are encoded with the plus sign (+). If the value is false, space characters are converted to %20, but no other reserved characters are encoded. The default value is false.

Example 

This example shows how URLs are percent-encoded when the value of the second operand is true or false.

1<script runat="server">
2  var baseURL = "http://www.example.com?value=12+3 12;3";
3  var urlEncodeDefault = Platform.Function.UrlEncode(baseURL);
4  var urlEncodeOperand2True = Platform.Function.UrlEncode(baseURL, true);
5</script>
6
7<table>
8  <tr>
9    <th>Description</th>
10    <th>Value</th>
11  </tr>
12  <tr>
13    <td>Base URL</td>
14    <td><ctrl:var name="baseURL" /></td>
15  </tr>
16  <tr>
17    <td>Value when operand 2 equals false (default)</td>
18    <td><ctrl:var name="urlEncodeDefault" /></td>
19  </tr>
20  <tr>
21    <td>Value when operand 2 equals true</td>
22    <td><ctrl:var name="urlEncodeOperand2True" /></td>
23  </tr>
24</table>

The example outputs these values.

DescriptionValue
Base URLhttp://www.example.com?value=12+3 12;3
Value when operand 2 equals false (default)http://www.example.com?value=12+3%2012;3
Value when operand 2 equals truehttp://www.example.com?value%3d12%2b3+12%3b3