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.
UrlEncode(1, 2)
| Ordinal | Type | Description |
|---|---|---|
1 | String | Required. The URL to encode. The specified value must be a complete URL in order to be percent-encoded. |
2 | Boolean | Specifies 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. |
This example shows how URLs are percent-encoded when the value of the second operand is true or false.
The example outputs these values.
| Description | Value |
|---|---|
| Base URL | http://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 true | http://www.example.com?value%3d12%2b3+12%3b3 |