{urlencode:string}

Description

URL-encodes a string for safe use in a URL - the counterpart of PHP urlencode(). Spaces become plus signs and every character outside A-Z a-z 0-9 and the set - _ . * is percent-encoded (for example & becomes %26). This is form encoding (application/x-www-form-urlencoded). Deprecated: prefer rawurlencode, which is RFC 3986 compliant and encodes a space as %20. Takes one argument; a literal colon inside it must be escaped as #: so it is not read as a parameter separator.

Parameters

string required

The text to URL-encode. Any characters that are not safe in a URL are percent-encoded; spaces become plus signs. If it contains a colon, escape the colon as #: so it is not treated as a parameter separator.

Examples

test{urlencode:hello world}
Expectedhello+world
Actualhello+world
URL-encodes a string (PHP urlencode): spaces become + - unlike {rawurlencode:} which uses %20.
test{urlencode:Praha & Brno}
ExpectedPraha+%26+Brno
ActualPraha+%26+Brno
Spaces become +, and reserved characters like & become percent-encoded (%26).
test{urlencode:a/b?c=d&e=f}
Expecteda%2Fb%3Fc%3Dd%26e%3Df
Actuala%2Fb%3Fc%3Dd%26e%3Df
Slash, question mark and equals are all percent-encoded, so the result is safe as a single query-string value.
test{urlencode:file-name_v2.txt}
Expectedfile-name_v2.txt
Actualfile-name_v2.txt
Letters, digits and the characters - _ . (plus *) are left unchanged by PHP urlencode.
test{urlencode:http#://www.example.org/p?q=a b}
Expectedhttp%3A%2F%2Fwww.example.org%2Fp%3Fq%3Da+b
Actualhttp%3A%2F%2Fwww.example.org%2Fp%3Fq%3Da+b
A bare colon would be read as a parameter separator, so write http#:// (the #: escape) to pass the literal URL as one argument.
test{urlencode:hello world}=={rawurlencode:hello world}
Expectedhello+world==hello%20world
Actualhello+world==hello%20world
urlencode (form encoding) turns a space into +, while rawurlencode (RFC 3986) turns it into %20. Prefer rawurlencode for path segments; urlencode is deprecated.
Deprecated: - use RFC 3986 compliant {rawurlencode}