Home > Article > Backend Development > What should I do if PHP receives garbled Chinese parameters from GET?
Solution to the problem that PHP receives garbled Chinese parameters in GET: 1. Use the iconv function, the code is [$str = iconv("gb2312", "utf-8", $str)]; 2. Use the function [ encoding], the code is [mb_convert_encoding $str].
Solution to PHP receiving garbled Chinese parameters in GET:
If the address generated by the gbk-encoded page is linked to For utf-8 pages and gbk pages, the Chinese is encoded in the gbk format and sent to the next page, so garbled characters will definitely appear after receiving the utf-8 encoding.
The url rewriting module of IIS, the rewritten Chinese encoding is also gbk. If your page is utf-8 encoding, then the rewriting parameters will be invalid.
In situations like these, we need to use PHP’s built-in transcoding function to deal with encoding problems:
Option 1:
$str = iconv("gb2312","utf-8",$str);
Option 2 :
mb_convert_encoding($str, "utf-8", "gb2312");
Related learning recommendations: php programming (video)
The above is the detailed content of What should I do if PHP receives garbled Chinese parameters from GET?. For more information, please follow other related articles on the PHP Chinese website!