How to convert json unicode to Chinese in php

藏色散人
Release: 2023-03-17 20:18:01
Original
2837 people have browsed it

php method to convert json unicode to Chinese: 1. Use the "json_encode($log['result_data'],JSON_UNESCAPED_UNICODE);" method to convert; 2. Use "function unicodeDecode($unicode_str){.. .}" method to convert.

How to convert json unicode to Chinese in php

The operating environment of this tutorial: Windows 10 system, PHP version 8.1, DELL G3 computer

How to convert json unicode to Chinese in php ?

PHP converts unicode encoded json string to Chinese

Chinese in json is encoded

$s = '[{"param_name":"email","param_caption":"\u90ae\u7bb1","operator":"\u5305\u542b","value":"aaaa\u5927\u592b\u6492"}]';
Copy after login

Convert Chinese encoding to Chinese

Method 1.

json_encode($log['result_data'],JSON_UNESCAPED_UNICODE);
Copy after login

Method 2.

/** * 把unicode编码的字符串转为人眼可看的字符串 * @param $unicode_str * * @return string */ function unicodeDecode($unicode_str){ $unicode_str = str_replace('"', '\"', $unicode_str); $unicode_str = str_replace("'", "\'", $unicode_str); $json = '{"str":"'.$unicode_str.'"}'; $arr = json_decode($json,true); if(empty($arr)){ return ''; } return $arr['str']; }
Copy after login

Result:

[{"param_name":"email","param_caption":"邮箱","operator":"包含","value":"aaaa大夫撒"}]
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to convert json unicode to Chinese in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!