PHP Json Chinese processing solution

Source: Internet
Author: User
This article mainly introduces PHP's Json Chinese processing solution, which involves php coding and conversion related operation skills and has some reference value, for more information about PHP Json processing solutions, see the following section. We will share this with you for your reference. The details are as follows:

Json is a widely used format for passing strings. it is easier to understand AND operate than xml. in php, there are two functions, json_encode () AND json_deconde (). However, json does not support Chinese very well. if json_encode () is used to process such as arrays, and if the array contains Chinese characters, it will be blank.

One way to solve Chinese is to convert Chinese to another encoding format, then use json_encode (), and then decode the json string. There is another way to solve this problem in the new php version, which is shown in the following code.

Sample code:

 'Guangdong ', 'goods' => 'Cookies'); $ arr = json_encode ($ arrayName); echo $ arr ."
"; Var_dump (json_decode ($ arr); echo"
"; Echo urldecode (json_encode (ch_json ($ arrayName )))."
";/* Require php versions above 5.4 echo json_encode ($ arrayName, JSON_UNESCAPED_UNICODE); */function ch_json ($ arr) {if (is_array ($ arr )) {foreach ($ arr as $ key =>$ value) {$ arr [urlencode ($ key)] = ch_json ($ value );}} else {return urlencode ($ arr);} return $ arr ;}?>

I hope this article will help you with PHP programming.

For more articles about PHP's Json processing solution, please refer to PHP's Chinese website!

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.