PHP Chinese URL encoding and decoding detailed instructions_PHP tutorial

WBOY
Release: 2016-07-13 10:54:00
Original
877 people have browsed it

, 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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632353.htmlTechArticle, the string decoded by urldecode() and rawurldecode() is encoded in UTF-8 format. If the URL is If it contains Chinese and the page setting is not UTF-8, the decoded string must be...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template