Introduction: This is a detailed page on PHP's urlencode () function. It introduces PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 343575 'rolling = 'no'>
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://ud03.kinoko.name/ .rar-> the browser automatically converts to-> http://ud03.kinoko.name/%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://ud03.kinoko.name/ .rar-> the browser automatically converts to-> http://ud03.kinoko.name/%E4%B8%AD%E6%96%87.rar
Urlencode in PHP:
<? PHP
// 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:
<? PHP
$ Url = 'HTTP: // ud03.kinoko. Name/ .rar ';
Echo urlencode (mb_convert_encoding ($ URL, 'utf-8', 'gb2312 '). "\ n ";
Echo rawurlencode (mb_convert_encoding ($ URL, 'utf-8', 'gb2312 '). "\ n ";
// Http%3a%2f%2fud03.kinoko.name%2f%e4%b8%ad%e6%96%87.rar
?>
Instance:
<? PHP
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@ud03.kinoko.name/Chinese/ .rar ";
Echo parseurl ($ URL );
// Ftp: // ud03: password@ud03.kinoko.name/% 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://ud03.kinoko.name/%E4%B8%AD%E6%96%87.rarhttp%3A%2F%2Fud03.kinoko.name%2F%E4%B8%AD%E6%96%87.rar
This article source web bar http://www.wangyeba.com
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/343575.html pageno: 5.