When the website project uses gb2312 as the project encoding, since different browsers may encode Chinese characters differently, some will encode Chinese as website encoding, and some will encode Chinese as utf-8, when receiving parameters in the background Garbled errors will occur. A better solution is to identify the Chinese characters in the parameters and convert them if they are not gb2312.
$typeName = $_GET['typeName']; $encode = mb_detect_encoding($typeName,'CP936,UTF-8') ; //如果是CP936,就是gbk编码,如果是UTF-8, 就是utf-8编码 if ($encode =='UTF-8') { //再调用转换成utf-8编码的函数,最终确保是utf-8 $typeName = iconv("utf-8","gb2312",$typeName); }
The above introduces the solution to garbled PHP parameters, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.