URLEncode: a pointer to the Chinese characters in the url of a Web page. The most common method is to enter Chinese Characters in search engines such as Baidu and Google, generate a webpage URL that has passed the Encode.
URLEncode: a pointer to the Chinese characters in the url of a Web page. The most common method is to enter Chinese Characters in search engines such as Baidu and Google, generate a webpage URL that has passed the Encode.
There are two URLEncode methods. One is the traditional GB2312-based Encode (Baidu, Yisou, etc ), another is UTF-8-based Encode (Google, Yahoo, etc ).
This tool implements two methods of Encode and Decode:
Chinese-> GB2312 Encode-> % D6 % D0 % CE % C4
English-> UTF-8 Encode-> % E4 % B8 % AD % E6 % 96% 87
URLEncode in Html:
In the html file encoded as GB2312: http://s.jb51.net/ .rar-> the browser automatically converts to-> http://s.jb51.net/%D6%D0%CE%C4.rar
Note: Firefox does not support the Chinese URL of GB2312 Encode, because it is the UTF-8 code by default to send the URL, but ftp: // protocol can, I tried, I think this is a Firefox bug.
In the html file encoded as UTF-8: http://s.jb51.net/ .rar-> the browser automatically converts to-> http://s.jb51.net/%E4%B8%AD%E6%96%87.rar
URLEncode in PHP:
The Code is as follows:
// GB2312 Encode
Echo urlencode ("Chinese-_."). "\ n"; // % D6 % D0 % CE % C4-_. +
Echo urldecode ("% D6 % D0 % CE % C4-_."). "\ n"; // Chinese -_.
Echo rawurlencode ("Chinese-_."). "\ n"; // % D6 % D0 % CE % C4-_. % 20
Echo rawurldecode ("% D6 % D0 % CE % C4-_."). "\ n"; // Chinese -_.
?>
All non-alphanumeric characters except "-_." will be replaced with a semicolon "%" followed by two hexadecimal numbers.
The difference between urlencode and rawurlencode: urlencode encodes the space into the plus sign "+", and rawurlencode encodes the space into the plus sign "% 20 ".
If you want to use the UTF-8's Encode, there are two ways:
1. Save the file as a UTF-8 file, directly use urlencode, rawurlencode.
Ii. Use the mb_convert_encoding function:
The Code is as follows:
$ Url = 'HTTP: // s.jb51.net/ .rar ';
Echo urlencode (mb_convert_encoding ($ url, 'utf-8', 'gb2312 '). "\ n ";
Echo rawurlencode (mb_convert_encoding ($ url, 'utf-8', 'gb2312 '). "\ n ";
// Http%3A%2F%2Fs.jb51.net%2F%E4%B8%AD%E6%96%87.rar
?>
Instance:
The Code is as follows:
Function parseurl ($ url = "")
{
$ Url = rawurlencode (mb_convert_encoding ($ url, 'gb2312', 'utf-8 '));
$ A = array ("% 3A", "% 2F", "% 40 ");
$ B = array (":","/","@");
$ Url = str_replace ($ a, $ B, $ url );
Return $ url;
}
$ Url = "ftp: // ud03: password@s.jb51.net/Chinese/ .rar ";
Echo parseurl ($ url );
// Ftp: // ud03: password@s.jb51.net/% D6 % D0 % CE % C4/127d6%d0%ce%c4.rar
?>
URLEncode in JavaScript:
Example: % E4 % B8 % AD % E6 % 96% 87-_. % 20% E4 % B8 % AD % E6 % 96% 87-_. % 20
EncodeURI does not encode the following characters: ":", "/", ";", "?" And.
Such as: http://s.jb51.net/%E4%B8%AD%E6%96%87.rarhttp%3A%2F%2Fs.jb51.net%2F%E4%B8%AD%E6%96%87.rar