PHP url address bar transfer Chinese garbled code solution set

  • 2020-03-31 20:53:15
  • OfStack

PHP address bar down $_GET,urlencode and urldecode usage
Url encoding
Syntax: string urlencode(string STR);
Return value: string
Type of function: code processing
Such as:


<?php
$ChineseName=" My name is Chinese ";
$EncodeStr=urlencode($ChineseName);
echo "<a href=/cgi/personal.cgi?name=$EncodeStr> My name </a>";
?>

Url decoding
Restore the url-encoded string.
Syntax: string urldecode(string STR);
Return value: string
Type of function: code processing
Such as:
To the previous Chinese processing display

<?php
$DecodeStr=urldecode($_GET['name']);//You may not even have to decode it, because the browser will do it for you automatically
echo $DecodeStr;
?>

Get reg.php directly? Gh = x;

  / / trade union registration

$gonghui = $_GET [' h '];

The acquired $gonghui is gb2312 code output to display garbled code on utf-8 web page

to

  / / union login parameters
  $gonghui = $_GET [' h '];
  $gonghui = mb_convert_encoding($gonghui, "utf-8 ", "gb2312");

  It should be fine

Transform the entire page

This method is suitable for all coding environments. This USES & PI for all character sets other than the first 128 characters (display characters);   NCR (Numeric character reference, such as "Chinese characters" will be converted to "汉 The & # 23383;" In any coding environment, the page can be displayed normally.

Add the following three lines of code to the header of the PHP file:


mb_internal_encoding("gb2312");  //Gb2312 here is the original code & NBSP; for your website;      
mb_http_output("HTML-ENTITIES");     
ob_start('mb_output_handler');  

Using the mb_convert_encoding function requires PHP's mbstring (multi-byte string) extension to be enabled.

1. Windows server environment
Edit php.ini file, will; Extension =php_mbstring.dll; Remove and restart the web server.

2. Linux server environment
Add the --enable-mbstring=cn compilation parameter when compiling the configuration, and then compile and install PHP.

Third reference method for other netizens:
// method urldecode
$url = 'aaa. PHP? Region = '. Urldecode (" sichuan province ");
< A href = "< ? PHP echo $url; ? >" > Aaa < / a>

// method 2 base64_encode

< ?
$test = "sichuan province";
$test1 = base64_encode ($test);
Echo '< A href = "www.jb51.net? Region = $test1 "> Aaa < / a> ';
? >

The other page is solved using base64_decode

Base64_decode ($region);

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 ~ #


Related articles: