|uri_escape( $string )|
|uri_escape( $string, $unsafe )||
Replaces each unsafe character in the $string with the corresponding
escape sequence and returns the result. The $string argument should
be a string of bytes. The uri_escape() function will croak if given a
characters with code above 255. Use uri_escape_utf8() if you know you
have such chars or/and want chars in the 128 .. 255 range treated as
The uri_escape() function takes an optional second argument that overrides the set of characters that are to be escaped. The set is specified as a string that can be used in a regular expression character class (between [ ]). E.g.:
The default set of characters to be escaped is all those which are not part of the unreserved character class shown above as well as the reserved characters. I.e. the default is:
|uri_escape_utf8( $string )|
|uri_escape_utf8( $string, $unsafe )||
Works like uri_escape(), but will encode chars as UTF-8 before
escaping them. This makes this function able do deal with characters
with code above 255 in $string. Note that chars in the 128 .. 255
range will be escaped differently by this function compared to what
uri_escape() would. For chars in the 0 .. 127 range there is no
will be the same as:
but will even work for perl-5.6 for chars in the 128 .. 255 range.
Returns a string with each %XX sequence replaced with the actual byte
This does the same as:
but does not modify the string in-place as this RE would. Using the uri_unescape() function instead of the RE might make the code look cleaner and is a few characters less to type.
In a simple benchmark test I did, calling the function (instead of the inline RE above) if a few chars were unescaped was something like 40% slower, and something like 700% slower if none were. If you are going to unescape a lot of times it might be a good idea to inline the RE.
If the uri_unescape() function is passed multiple strings, then each one is returned unescaped.
Copyright 1995-2004 Gisle Aas.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|perl v5.12.2||URI::Escape (3)||2010-08-22|