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