Avoiding Unicode Escape Sequences in PHP's JSON Encoding
When using PHP's json_encode function with UTF-8 data, special characters may be represented using Unicode escape sequences. This can be undesirable for certain applications.
Question: How can PHP's json_encode be used to output UTF-8 characters without Unicode escape sequences?
Answer:
"{"a":"u00e1"}" and {"a":"á"}" represent the same JSON document and will be decoded similarly. However, in PHP 5.4 and later, the JSON_UNESCAPED_UNICODE option can be used with json_encode` to produce plain output without escape sequences.
For earlier PHP versions, an alternative JSON encoder can be implemented or used, such as Pear's JSON encoder with the following modification: remove lines 349 to 433, which handle Unicode escape sequences.
The above is the detailed content of How to Encode UTF-8 Characters in JSON Without Using Unicode Escape Sequences in PHP?. For more information, please follow other related articles on the PHP Chinese website!
if($res){
return json_encode(array('code'=>1,'msg'=>'成功'));
}else{
return json_encode(array('code'=>0,'msg'=>'失败'));
}
}
public function
}