Solving php parameter garbled code

WBOY
Release: 2016-08-08 09:26:09
Original
1149 people have browsed it

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);
}
Copy after login

For website coding issues and future expansion, it is recommended to use uft-8 encoding

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!