{
    "mode": "perldoc",
    "parameter": "URI::Escape",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/URI%3A%3AEscape/json",
    "generated": "2026-05-30T10:09:03Z",
    "synopsis": "use URI::Escape;\n$safe = uriescape(\"10% is enough\\n\");\n$verysafe = uriescape(\"foo\", \"\\0-\\377\");\n$str  = uriunescape($safe);",
    "sections": {
        "NAME": {
            "content": "URI::Escape - Percent-encode and percent-decode unsafe characters\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use URI::Escape;\n$safe = uriescape(\"10% is enough\\n\");\n$verysafe = uriescape(\"foo\", \"\\0-\\377\");\n$str  = uriunescape($safe);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module provides functions to percent-encode and percent-decode URI\nstrings as defined by RFC 3986. Percent-encoding URI's is informally\ncalled \"URI escaping\". This is the terminology used by this module,\nwhich predates the formalization of the terms by the RFC by several\nyears.\n\nA URI consists of a restricted set of characters. The restricted set of\ncharacters consists of digits, letters, and a few graphic symbols chosen\nfrom those common to most of the character encodings and input\nfacilities available to Internet users. They are made up of the\n\"unreserved\" and \"reserved\" character sets as defined in RFC 3986.\n\nunreserved    = ALPHA / DIGIT / \"-\" / \".\" / \"\" / \"~\"\nreserved      = \":\" / \"/\" / \"?\" / \"#\" / \"[\" / \"]\" / \"@\"\n\"!\" / \"$\" / \"&\" / \"'\" / \"(\" / \")\"\n/ \"*\" / \"+\" / \",\" / \";\" / \"=\"\n\nIn addition, any byte (octet) can be represented in a URI by an escape\nsequence: a triplet consisting of the character \"%\" followed by two\nhexadecimal digits. A byte can also be represented directly by a\ncharacter, using the US-ASCII character for that octet.\n\nSome of the characters are *reserved* for use as delimiters or as part\nof certain URI components. These must be escaped if they are to be\ntreated as ordinary data. Read RFC 3986 for further details.\n\nThe functions provided (and exported by default) from this module are:\n\nuriescape( $string )\nuriescape( $string, $unsafe )\nReplaces each unsafe character in the $string with the corresponding\nescape sequence and returns the result. The $string argument should\nbe a string of bytes. The uriescape() function will croak if given\na characters with code above 255. Use uriescapeutf8() if you know\nyou have such chars or/and want chars in the 128 .. 255 range\ntreated as UTF-8.\n\nThe uriescape() function takes an optional second argument that\noverrides the set of characters that are to be escaped. The set is\nspecified as a string that can be used in a regular expression\ncharacter class (between [ ]). E.g.:\n\n\"\\x00-\\x1f\\x7f-\\xff\"          # all control and hi-bit characters\n\"a-z\"                         # all lower case characters\n\"^A-Za-z\"                     # everything not a letter\n\nThe default set of characters to be escaped is all those which are\n*not* part of the \"unreserved\" character class shown above as well\nas the reserved characters. I.e. the default is:\n\n\"^A-Za-z0-9\\-\\.~\"\n\nuriescapeutf8( $string )\nuriescapeutf8( $string, $unsafe )\nWorks like uriescape(), but will encode chars as UTF-8 before\nescaping them. This makes this function able to deal with characters\nwith code above 255 in $string. Note that chars in the 128 .. 255\nrange will be escaped differently by this function compared to what\nuriescape() would. For chars in the 0 .. 127 range there is no\ndifference.\n\nEquivalent to:\n\nutf8::encode($string);\nmy $uri = uriescape($string);\n\nNote: JavaScript has a function called escape() that produces the\nsequence \"%uXXXX\" for chars in the 256 .. 65535 range. This function\nhas really nothing to do with URI escaping but some folks got\nconfused since it \"does the right thing\" in the 0 .. 255 range.\nBecause of this you sometimes see \"URIs\" with these kind of escapes.\nThe JavaScript encodeURIComponent() function is similar to\nuriescapeutf8().\n\nuriunescape($string,...)\nReturns a string with each %XX sequence replaced with the actual\nbyte (octet).\n\nThis does the same as:\n\n$string =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;\n\nbut does not modify the string in-place as this RE would. Using the\nuriunescape() function instead of the RE might make the code look\ncleaner and is a few characters less to type.\n\nIn a simple benchmark test I did, calling the function (instead of\nthe inline RE above) if a few chars were unescaped was something\nlike 40% slower, and something like 700% slower if none were. If you\nare going to unescape a lot of times it might be a good idea to\ninline the RE.\n\nIf the uriunescape() function is passed multiple strings, then each\none is returned unescaped.\n\nThe module can also export the %escapes hash, which contains the mapping\nfrom all 256 bytes to the corresponding escape codes. Lookup in this\nhash is faster than evaluating \"sprintf(\"%%%02X\", ord($byte))\" each\ntime.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "URI\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright 1995-2004 Gisle Aas.\n\nThis program is free software; you can redistribute it and/or modify it\nunder the same terms as Perl itself.\n",
            "subsections": []
        }
    },
    "summary": "URI::Escape - Percent-encode and percent-decode unsafe characters",
    "flags": [],
    "examples": [],
    "see_also": []
}