This article introduces the solution to PHPjson_encode Chinese garbled text. if you need it, refer to JSON
The following PHP code can solve the following problems:
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 );
}