PHP json_encode encryption, some Chinese characters show no urgent solution

Source: Internet
Author: User
After PHP json_encode encryption, some Chinese characters show no urgency
$e =mb_detect_encoding ($STR) Output character encoding type, how can this be?
ASCII-------------
UTF-8-------------, Harry
UTF-8-------------, Zhao Liu
ASCII-------------2014-07-16
-------------e-Commerce brand marketing Department
-------------Job Briefing
UTF-8-------------not archived
UTF-8-------------not Sent
-------------Manager's Office
ASCII-------------2
UTF-8-------------After the text is only required to select Xwould after the system will be automatically generated
UTF-8-------------who am I?
ASCII-------------11
ASCII-------------2014
ASCII-------------
-------------Testing Department
ASCII-------------
UTF-8-------------Li Gang, Guo Meimei, Zhao Zhiyong, Zhang Tanxin
ASCII-------------Admin
The total number of periods and year of the-------------work briefings can be automatically generated by the system and can be viewed in the list of posts
UTF-8-------------Research and Development Center
-------------Group leader
-------------Urgent
UTF-8-------------Common
ASCII-------------
ASCII-------------

After using Json_encode array encryption, the output of the Chinese character part is empty, what's the matter?
Heroes, do you have a good solution? Emergency


------Solution--------------------
Your original data is GBK, which cannot be accepted by Json_encode.
Json_encode only accepts UTF-8 encoded data, so GBK characters are discarded because they cannot be recognized.
Only a small number of character combinations have been incorrectly interpreted as utf-8 double-byte characters and have been preserved, causing your doubts, if not left, to make things clearer.

So if you need to generate JSON, you need to do a bit of transcoding.
Array_walk_recursive ($ar, function (& $s) {$s = Iconv (' GBK ', ' utf-8 ', $s);});

If the data is read from MySQL, it is only required to execute once before reading
mysql_query (' Set names UTF8 ');

It's Bob.

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