Home > Backend Development > PHP Tutorial > 使用json_encode获取中文unicode的有关问题

使用json_encode获取中文unicode的有关问题

WBOY
Release: 2016-06-13 11:54:09
Original
1085 people have browsed it

使用json_encode获取中文unicode的问题
简单的数据库查询程序,数据库表里的中文保存的是中文unicode编码,例如中国在库里显示的是\u3537\u3456这样,

接收输入的中文是utf-8, 使用json_encode的自动中文转码功能可以获得unicode,可是问题来了,如果从转码后的字符串里获取
unicode呢,请大家帮忙给点思路啊?

例子代码如下

$str_input = "go南京trip"; //待查询的字符串
$str_input = json_encode($str_input);

$str_query = "go\u3537\3642trip";目标字符串

如何从$str_input获取$str_query呢? 
------解决方案--------------------

$str_input = "go南京trip";<br />$str_query = trim(json_encode($str_input), '"'); <br /><br />echo $str_query; <br />
Copy after login
得到的是 go\u5357\u4eactrip

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template