Home > Article > Backend Development > PHP Chinese URL encoding and decoding detailed instructions_PHP tutorial
, urldecode() and rawurldecode() decode the string in UTF-8 format. If the URL contains Chinese and the page setting is not UTF-8, the decoded string must be encoded. Conversion to display normally
php tutorial Chinese url encoding and decoding details
In php, urlencode and rawurlencode encode Chinese
string urlencode (string str)
Returns a string in which all non-alphanumeric characters except -_. are replaced with a percent sign (%) followed by two hexadecimal digits. This is the encoding described in RFC 1738, and is intended to protect literal characters from being interpreted as special URL delimiters, and to protect the URL format from being garbled by character conversions used by the transport medium (like some email systems)
*/
$a ='?a=中文';
$urlencode =urlencode($a);
echo $urlencode; //%3fa%3d%d6%d0%ce%c4
/*
string rawurldecode (string str)
Returns a string in which the percent sign (%) followed by a sequence of two hexadecimal digits will be replaced with literal characters.
*/
$c = rawurlencode($urlencode);///a%253d%25d6%25d0%25ce%25c4;
echo $c;
/*
One thing to note is that the string decoded by urldecode() and rawurldecode() is encoded in utf-8 format. If the url contains Chinese and the page setting is not utf-8, you must Convert the decoded string to display it normally