PHPjson_encode solution to Chinese garbled characters _ PHP Tutorial

Source: Internet
Author: User
PHPjson_encode. The following PHP code can solve the following problems: 1. the string after the json_encodeUTF8 code is Chinese cannot be read 2. json_encode multi-level array Chinese garbled problem 3. the following PHP code solves the following problems when the json_encode array contains a line change:
1. the string after the json_encode UTF8 code is Chinese cannot be read
2. Chinese garbled characters in json_encode multi-level arrays
3. an error occurred while changing the line in the json_encode array.
4. question about the Chinese character in the json_encode array

The code is as follows:


Function _ encode ($ arr)
{
$ Na = array ();
Foreach ($ arr as $ k => $ value ){
$ Na [_ urlencode ($ k)] = _ urlencode ($ value );
}
Return addcslashes (urldecode (json_encode ($ na), "\ r \ n ");
}

Function _ urlencode ($ elem)
{
If (is_array ($ elem )){
Foreach ($ elem as $ k => $ v ){
$ Na [_ urlencode ($ k)] = _ urlencode ($ v );
}
Return $ na;
}
Return urlencode ($ elem );
}

Listing 1. the json_encode UTF8 character string cannot be read. 2. Chinese garbled characters in the json_encode multi-level array. 3. the json_encode array contains changing rows...

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.