UrlEncode()
Modifies a string to only include characters that are safe to use in URLs.
The URLEncode()
function has three parameters:
urlToEncode
(string): Required. The string to convert to a format that is safe to include in URLs.boolEncodeAllChars
(boolean): Iftrue
, the function converts all spaces and non-ASCII characters in a URL parameter string to their hexadecimal character codes. Iffalse
, the function only converts spaces in a URL parameter string to the hexadecimal character code%20
, and leaves other characters unchanged. The default value isfalse
.boolEncodeAllStrings
(boolean): Iftrue
, the function converts any text string that you pass as the first parameter into a version that is safe to use in URLs. Iffalse
, the function only converts a string into a URL-safe version if the unsafe characters are part of a URL parameter string.
To use this function, pass it a URL to encode. This example converts a URL that contains a parameter string that contains a space in the key name.
The function returns a URL in which only space characters are converted into hexadecimal characters. It doesn’t convert the Unicode characters that are contained in the string.
You can control which characters the function converts by changing the value of the boolEncodeAllChars
parameter. This example converts all non-ASCII characters to hexadecimal encodings.
The function returns a string in which all of the non-ASCII characters in the parameter string are converted to their hexadecimal equivalents.
You can convert a non-URL string into a URL-encoded string by changing the value of the boolEncodeAllStrings
parameter. This example converts a string of text that isn’t a URL into a string that is safe to include in a URL.
The function returns a string in which all of the non-ASCII characters and spaces are converted to a URL-safe format.