Home  >  Article  >  Backend Development  >  What should I do if PHP receives garbled Chinese parameters from GET?

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

coldplay.xixi
coldplay.xixiOriginal
2020-08-17 09:36:342322browse

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);

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!

Statement:
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