PHP5.4 only supports the Json_unescaped_unicode parameter, which allows Chinese characters to be json_encode without escaping, reducing the amount of data transferred. But in PHP5.3, you have to write a function to implement, the following is the solution:
/**
* The JSON encoding of the variable
* @param mixed value to be encoded value, except resource type, can be any data type, the function can only accept UTF-8 encoded data
* @return s Tring returns the JSON form/
function json_encode_ex ($value)
{
if Version_compare (Php_version, ') of value values 5.4.0 ', ' < ')
{
$str = Json_encode ($value);
$str = Preg_replace_callback (
"#\\\u (0-9a-f]{4}) #i",
function ($matchs)
{return
iconv (' Ucs-2be ', ' UTF-8 ', pack (' H4 ', $matchs [1]));
},
$str
)
; return $str;
}
else
{return
json_encode ($value, Json_unescaped_unicode);
}
}
To determine the version of PHP, if less than 5.4 then use a custom function to implement, if it is 5.4 and above version of the use of Json_unescaped_unicode.
The above is the PHP json_encode incompatible Json_unescaped_unicode solution, I hope to give you a reference to learn more PHP syntax, we can pay attention to the "PHP5 Online Handbook", but also hope that we support the cloud habitat community.