php get garbled solution: 1. Use the iconv function to convert the string according to the required character encoding; 2. Use mb_convert_encoding to convert the encoding.
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How to solve the garbled problem of php get? ?
The reasons and solutions for PHP receiving garbled Chinese parameters in GET
Option 1:
$str = iconv("gb2312","utf-8",$str);
Option 2:
mb_convert_encoding($str, "utf-8", "gb2312");
Related introduction:
iconv : Convert the string according to the required character encoding
Description
iconv(string $in_charset, string $out_charset, string $str): string
Convert the string str from in_charset to out_charset.
Parameters
in_charset
Input character set.
out_charset
Output character set.
If you add the string //TRANSLIT after out_charset, the transliteration function will be enabled. This means that when a character cannot be represented by the target character set, it can be approximated by one or more similar characters. If you add the string //IGNORE, characters that cannot be expressed in the target character set will be silently discarded. Otherwise, an E_NOTICE is caused and false is returned.
WARNING
//TRANSLIT operation details are highly dependent on the system's iconv() implementation (see ICONV_IMPL). It is reported that the implementation on some systems will directly ignore //TRANSLIT, so the conversion may fail and out_charset will be unqualified.
str
The string to be converted.
Return value
Returns the converted string, or returns false on failure.
php mb_convert_encoding: php built-in encoding conversion method.
Method prototype: string mb_convert_encoding ( string $str , string $to_encoding [, mixed $from_encoding = mb_internal_encoding() ] )
Convert the character encoding of string type str from optional from_encoding to to_encoding.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to solve the garbled problem of php get. For more information, please follow other related articles on the PHP Chinese website!