The following PHP code can solve the following problems:
1.json_encode The string after UTF8 code Chinese cannot be read
2.json_encode multi-level array Chinese garbled problem
3.json_encode error when the array contains line breaks
4.json_encode The problem with the keys in the array being Chinese
Copy the code 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);
}
http://www.bkjia.com/PHPjc/313650.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/313650.htmlTechArticleThe following PHP code can solve the following problems: 1.json_encode The string after UTF8 code Chinese cannot be read 2.json_encode Multi-level array Chinese garbled problem 3. When the json_encode array contains line breaks...