PHP json_encode Format Chinese Problem solving method _php Tutorial

Source: Internet
Author: User
1. Cause Analysis:

When you save to the database! MySQL does not store Unicode characters:

MySQL is only supported from basic multi-lingual plane characters (0X0000-0XFFFF). Please try to store a synonym instead:)

Update: MySQL on 5.5.3 (which has not yet GA), supports supplemental characters if you use UTF8MB4 encoding.

When Json_encode Chinese, I will encode the characters into "uxxxx".

And in the database, "" is blocked, directly into the "uxxxx"

2. Problem solving:

Know what the reason is to solve the problem, you can choose other storage methods;

or the remedy. Further escape "" to ", to preserve" "

Our solutions:

1. Avoid json_encode convert Chinese to Unicode encoding.

PHP5.4 version, a new option has been added to JSON: Json_unescaped_unicode. With this option, the Chinese is not automatically encoded.

$test = Json_encode ("Shenzhen", Json_unescaped_unicode);

2. After urlencode,json_encode the Chinese text section, and then using the UrlDecode, it is also possible to ensure that the language is not converted to Unicode.

$test =urldecode (Json_encode (' Brief ' =>urlencode (' Introduction '), ' title ' =>urlencode (title)));

3. Further escape "" to "" to avoid Unicode as a special character removal by MySQL before "

http://www.bkjia.com/PHPjc/371391.html www.bkjia.com true http://www.bkjia.com/PHPjc/371391.html techarticle 1. Cause analysis: When storing to the database! MySQL does not store Unicode characters: MySQL is only supported from basic Multilingual Plane characters (00000-0XFFFF). Please try to store a synonym opposite ...

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