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)

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.

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

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