01 Output Chinese garbled
02json_encode () escaped to JSON storage, the default is to convert Chinese into Unicode
03
Two PHP files or HTML files that have been developed. Chinese encoding is not utf-8, select txt text or EditPlus open, Save as utf-8. Then modify the code to set the encoding to Utf-8.
When compiling, first look at the encoding of the text. Then follow the encoding format. To display or perform
If the text is encoded as gb2312 or GBK. Use the Phpstrom to open a Chinese garbled. You need to look at the lower right corner. Whether to read and display in the UTF-8 format
=========== MySQL Chinese garbled cmd
See if the encoding format is GBK. The CMD panel is displayed by default in GBK format.
Show variables like '%char% '; View variable blur match all variable settings in MySQL
Set names GBK; Sets the client character set to GBK to read data. Return to CMD panel
If the client code is not set to GBK. Search for Chinese matches is not a result
============
Header ("Content-type:text/html;charset=utf-8");
Echo ' <pre> ';
Echo ' <meta http-equiv= "Content-type" content= "Text/html:charset=utf-8" > ";
Var_dump ($data);
===========JSON data in Chinese direct storage without turning into Unicode
function json_encode_ex ($value)
{
if (version_compare (php_version, ' 5.4.0 ', ' < '))
{
$str = Json_encode ($value);
$str = Preg_replace_callback (
"#\\\u ([0-9a-f]{4}) #i",
function ($matchs)
{
Return Iconv (' Ucs-2be ', ' UTF-8 ', pack (' H4 ', $matchs [1]));
},
$str
);
return $str;
}
Else
{
Return Json_encode ($value, json_unescaped_unicode);
}
}
Chinese garbled processing