What should I do if PHP receives garbled Chinese parameters from GET?

coldplay.xixi
Release: 2023-03-04 15:14:01
Original
2245 people have browsed it

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].

What should I do if PHP receives garbled Chinese parameters from GET?

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

Option 2 :

mb_convert_encoding($str, "utf-8", "gb2312");
Copy after login

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!

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
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!