When you do Json_encode in php5.2. Chinese will be Unicode encoded,
php5.3 added the options parameter,
After 5.4 Join Json_unescaped_unicode, this parameter, do not need to do escape and UNICODE processing.
So we need to do a deal on Chinese before 5.4.
5.4 The inside of the treatment
Json_encode ($str, Json_unescaped_unicode);
Before 5.4, there are two ways to handle
Method 1
function Encode_json ($str) { $code = Json_encode ($str); return Preg_replace $code ); }
Method 1. In practical application there is a problem, some characters will be dropped, more than why, such as String: "Date 11.2" will be changed to "date." 2 "
Method 2.
First to deal with the need to do urlencode processing, and then Json_encode, and finally do urldecode processing
functionEncode_json ($str) { return UrlDecode(Json_encode (Url_encode ($str))); } /** * */ functionUrl_encode ($str) { if(Is_array($str)) { foreach($str as $key=$value) { $str[UrlEncode($key)] = Url_encode ($value); } } Else { $str=UrlEncode($str); } return $str; }
PHP json_encode Chinese is transcoded problem