PHP Address bar Chinese $_get down after garbled, UrlEncode and urldecode usage of the detailed
URL encoding
Syntax: string urlencode (String str);
return value: String
Function type: Encoding processing
For example:
Copy CodeThe code is as follows:
$ChineseName = "My name is Chinese, oh";
$EncodeStr =urlencode ($ChineseName);
echo "My Name";
?>
URL decoding
Restores the URL-encoded string.
Syntax: string urldecode (String str);
return value: String
Function type: Encoding processing
For example:
To handle the Chinese in front of the display
Copy CodeThe code is as follows:
$DecodeStr =urldecode ($_get[' name ');//You may not have to decode it, because the browser will automatically decode it for you.
Echo $DecodeStr;
?>
about PHP using get method from URL to get the problem of Chinese garbled
Use $gonghui = Iconv ("gb2312", "UTF-8", $gonghui), and another method code
/**
* Multi-byte string encoding conversion function
*
* @param string str needs to encode the converted strings
* @param string to_encoding specified to a certain encoding, such as: gb2312, GBK, utf-8, etc.
* @param mixed From_encoding Mix to specify the encoding of the original string, such as: Specify JIS, Eucjp-win, Sjis-win mixed code
* @return String
String mb_convert_encoding (String str, string to_encoding [, mixed from_encoding])
**/
The Mb_convert_encoding function is an internal multi-byte string encoding conversion function in PHP, which can support almost all encodings where it is needed. PHP >= 4.0.6, version 5 support.
Direct access to reg.php?gh= xxx;
Trade union log-in participation
$gonghui = $_get[' gh '];
Obtained $gonghui for gb2312 encoded output to UTF-8 Web page garbled display
Change into
Trade union log-in Parameters
$gonghui = $_get[' gh '];
$gonghui = mb_convert_encoding ($gonghui, "UTF-8", "gb2312");
It's normal.
Converting an entire page
This method applies to all coding environments. In this way, the character set of the first 128 characters (display character) is used in NCR (Numeric character reference, such as "kanji" will be converted to "Chinese characters" this form), so that the code in any encoding environment, the page can display normally.
Add the following three lines of code to the header of the PHP file:
Copy the Code code as follows:
Mb_internal_encoding ("gb2312"); The gb2312 here is the original code of your website.
Mb_http_output ("Html-entities");
Ob_start (' Mb_output_handler ');
Use the Mb_convert_encoding function to enable the PHP mbstring (multi-byte string) extension.
If there is no mbstring extension for PHP, you need to do the following to allow PHP to support the extension.
1. Windows Server Environment
Edit php.ini file, will; Extension=php_mbstring.dll in front of; Remove and restart the Web server.
2. Linux Server environment
When compiling the configuration, add the--ENABLE-MBSTRING=CN compile parameters, and then compile and install the PHP.
Other users of the third reference method:
Method One UrlDecode
$url = ' aaa.php?region= '. UrlDecode ("Sichuan Province");
">aaa
Method Two Base64_encode
$test = "Sichuan province";
$test 1=base64_encode ($test);
Echo ' AAA ';
?>
Another page using Base64_decode to unlock
Base64_decode ($region);
Method Three let the server support Chinese
[Root@dhcp ~]# Locale
Lang=zh_cn.utf-8
Lc_ctype= "Zh_cn.utf-8"
Lc_numeric= "Zh_cn.utf-8"
Lc_time=c
Lc_collate=c
lc_monetary= "Zh_cn.utf-8"
Lc_messages= "Zh_cn.utf-8"
Lc_paper= "Zh_cn.utf-8"
Lc_name= "Zh_cn.utf-8"
Lc_address= "Zh_cn.utf-8"
Lc_telephone= "Zh_cn.utf-8"
Lc_measurement= "Zh_cn.utf-8"
lc_identification= "Zh_cn.utf-8"
Lc_all=
[Root@dhcp ~]#
http://www.bkjia.com/PHPjc/322145.html www.bkjia.com true http://www.bkjia.com/PHPjc/322145.html techarticle PHP Address bar Chinese $_get down after garbled, UrlEncode and UrlDecode usage detailed URL encoding syntax: string urlencode (String str); return value: String function type: encoding processing such as: ...