The urlencode function encodes the input string parameters. The returned string contains -. ", all non-alphanumeric characters are replaced with a semicolon (%) followed by two hexadecimal numbers, and spaces are encoded as the plus sign (+ ). This function allows you to encode a string and use it in the request part of a URL. It also allows you to pass variables to the next page. 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 has two methods: the traditional GB2312-based Encode (Baidu, Yisou, etc.), and the UTF-8-based Encode (Google, Yahoo, etc ). This tool implements Encode and Decode in two ways respectively.
- Chinese-> GB2312 Encode-> % D6 % D0 % CE % C4
- English-> UTF-8 Encode-> % E4 % B8 % AD % E6 % 96% 87
URLEncode in HtmlIn the html file encoded as GB2312, http://www.nowamagic.net/ .rar-> the browser automatically converts to-> http://www.nowamagic.net/%D6%D0%CE%C4.rar Note: Firefox does not support the Chinese URL of the GB2312 Encode, because it is the UTF-8 encoding by default to send the URL, but ftp: // protocol can. Encode the UTF-8 in the html file, http://www.nowamagic.net/ .rar-> the browser automatically converts to-> http://www.nowamagic.net/%E4%B8%AD%E6%96%87.rar URLEncode in 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 a space into a plus sign (+)
- Rawurlencode encodes a space into a plus sign (% 20)
If you want to use the UTF-8's Encode, there are two ways:
- Save the file as a UTF-8 file, directly use urlencode, rawurlencode.
- Use the mb_convert_encoding function.
-
- $ Url = 'http: // www.nowamagic.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%2Fwww.nowamagic.net%2F%E4%B8%AD%E6%96%87.rar
- ?>
Instance:
-
- 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@www.nowamagic.net/Chinese/ .rar ";
- Echo parseurl ($ url );
- // Ftp: // ud03: password@www.nowamagic.net/% D6 % D0 % CE % C4/127d6%d0%ce%c4.rar
- ?>
URLEncode in JavaScript: % E4 % B8 % AD % E6 % 96% 87 -_. % 20% E4 % B8 % AD % E6 % 96% 87 -_. % 20, encodeURI does not encode the following characters: ":", "/", ";", "?" And.
|