UrlEncode: is a Web page URL contains Chinese characters encoding conversion method, UrlEncode there are two common ways, one is based on GB2312 Encode (Baidu, Yisou and other search engines use), The other is based on the UTF-8 encode (Google, Yahoo, etc.). Here's a look at the difference between encode and decode in two ways:
Encode,%D6%D0%CE%C4, GB2312, Chinese
Encode,%e4%b8%ad%e6%96%87, UTF-8, Chinese
UrlEncode in HTML pages:
HTML file encoded as GB2312: http://www.baidu.com/. RAR---browser automatically converted to Http://www.baidu.com/%D6%D0%CE%C4.rar
Later found that Firefox to GB2312 encode Chinese URL support is not good, because it is the default UTF-8 encoding to send URL, but ftp://protocol can, this should be considered a bug in Firefox.
Let's look at a code example of UrlEncode encoding conversion in PHP:
// examples of encode in GB2312 Echo UrlEncode // %d6%d0%ce%c4-_.+ Echo UrlDecode // Chinese-_. Echo Rawurlencode // %d6%d0%ce%c4-_.%20 Echo Rawurldecode // Chinese-_.
Except for "-_." All non-alphanumeric characters will be replaced with a percent percent "%" followed by a two-digit hexadecimal number.
The difference between UrlEncode and Rawurlencode: UrlEncode encodes a space as a plus "+", and Rawurlencode encodes a space as a plus "%20".
If you want to use UTF-8 's encode, there are two ways:
The first is to save the file as a UTF-8 file, directly using UrlEncode, Rawurlencode.
The second method is to use the Mb_convert_encoding function transformation, the sample code is as follows:
$url= ' http://www.baidu.com/Chinese. rar '; Echo UrlEncode (Mb_convert_encoding ($url, ' utf-8 ', ' gb2312 ')). " \ n "; Echo Rawurlencode (Mb_convert_encoding ($url, ' utf-8 ', ' gb2312 ')). " \ n ";
Note: encodeURI does not encode special characters such as ":", "/", ";", "?", "@".
PHP urlencode () function URL encoding conversion instance parsing