Chinese garbled processing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.