The reason why php parameters are garbled is because the encoding is inconsistent. The solution is to modify it to use uft-8 encoding. The modification code is such as "mb_detect_encoding($typeName,'CP936,UTF-8')".
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
Why are the parameters in php garbled?
Solution to garbled parameters in php
When the website project uses gb2312 as the project encoding, due to different browsers The encoding of Chinese characters may be different. Some will encode Chinese into website encoding, and some will encode Chinese into utf-8. Garbled errors will occur when receiving parameters in the background. 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); }
For website coding issues and future expansion, it is recommended to use uft-8 encoding
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of Why are the parameters passed in php garbled?. For more information, please follow other related articles on the PHP Chinese website!