{
    "mode": "perldoc",
    "parameter": "URI::Escape",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/URI%3A%3AEscape/json",
    "generated": "2026-06-12T11:11:12Z",
    "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 strings as defined by\nRFC 3986. Percent-encoding URI's is informally called \"URI escaping\". This is the terminology\nused by this module, which predates the formalization of the terms by the RFC by several years.\n\nA URI consists of a restricted set of characters. The restricted set of characters consists of\ndigits, letters, and a few graphic symbols chosen from those common to most of the character\nencodings and input facilities available to Internet users. They are made up of the \"unreserved\"\nand \"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 sequence: a triplet\nconsisting of the character \"%\" followed by two hexadecimal digits. A byte can also be\nrepresented directly by a character, using the US-ASCII character for that octet.\n\nSome of the characters are *reserved* for use as delimiters or as part of certain URI\ncomponents. These must be escaped if they are to be treated as ordinary data. Read RFC 3986 for\nfurther details.\n\nThe functions provided (and exported by default) from this module are:\n",
            "subsections": [
                {
                    "name": "uri_escape",
                    "content": ""
                },
                {
                    "name": "uri_escape",
                    "content": "Replaces each unsafe character in the $string with the corresponding escape sequence and\nreturns the result. The $string argument should be a string of bytes. The uriescape()\nfunction will croak if given a characters with code above 255. Use uriescapeutf8() if you\nknow you have such chars or/and want chars in the 128 .. 255 range treated as UTF-8.\n\nThe uriescape() function takes an optional second argument that overrides the set of\ncharacters that are to be escaped. The set is specified as a string that can be used in a\nregular expression character 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 *not* part of the\n\"unreserved\" character class shown above as well as the reserved characters. I.e. the\ndefault is:\n\n\"^A-Za-z0-9\\-\\.~\"\n"
                },
                {
                    "name": "uri_escape_utf8",
                    "content": ""
                },
                {
                    "name": "uri_escape_utf8",
                    "content": "Works like uriescape(), but will encode chars as UTF-8 before escaping them. This makes\nthis function able to deal with characters with code above 255 in $string. Note that chars\nin the 128 .. 255 range will be escaped differently by this function compared to what\nuriescape() would. For chars in the 0 .. 127 range there is no difference.\n\nEquivalent to:\n\nutf8::encode($string);\nmy $uri = uriescape($string);\n\nNote: JavaScript has a function called escape() that produces the sequence \"%uXXXX\" for\nchars in the 256 .. 65535 range. This function has really nothing to do with URI escaping\nbut some folks got confused since it \"does the right thing\" in the 0 .. 255 range. Because\nof this you sometimes see \"URIs\" with these kind of escapes. The JavaScript\nencodeURIComponent() function is similar to uriescapeutf8().\n"
                },
                {
                    "name": "uri_unescape",
                    "content": "Returns a string with each %XX sequence replaced with the actual byte (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 uriunescape() function\ninstead of the RE might make the code look cleaner and is a few characters less to type.\n\nIn a simple benchmark test I did, calling the function (instead of the inline RE above) if a\nfew chars were unescaped was something like 40% slower, and something like 700% slower if\nnone were. If you are going to unescape a lot of times it might be a good idea to inline the\nRE.\n\nIf the uriunescape() function is passed multiple strings, then each one is returned\nunescaped.\n\nThe module can also export the %escapes hash, which contains the mapping from all 256 bytes to\nthe corresponding escape codes. Lookup in this hash is faster than evaluating \"sprintf(\"%%%02X\","
                },
                {
                    "name": "ord",
                    "content": ""
                }
            ]
        },
        "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 under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "URI::Escape - Percent-encode and percent-decode unsafe characters",
    "flags": [],
    "examples": [],
    "see_also": []
}