php json_encode utf8 中文编码65u02f。怎么解决?

WBOY
Release: 2016-06-23 13:40:39
Original
1152 people have browsed it

mysql_query("set names 'utf8'");
Copy after login



已经写这个了,但是还是这样。。
mysql数据库也是utf8


回复讨论(解决方案)

json_encode 默认是将中文转换成 unicode 的 HTML 实体的
如果你的 php 版本大于等于 5.4.0, 则可以

$s = '中文';echo json_encode($s, JSON_UNESCAPED_UNICODE);
Copy after login
Copy after login
"中文"

json_encode 默认是将中文转换成 unicode 的 HTML 实体的
如果你的 php 版本大于等于 5.4.0, 则可以

$s = '中文';echo json_encode($s, JSON_UNESCAPED_UNICODE);
Copy after login
Copy after login
"中文"


我的版本是5.2.6的怎么做。

系统是mac的。。

那可以这样

$a = array('中文', aray('中文'));echo preg_replace_callback('/\\\u(.{4})/', 'foo', json_encode($a));function foo($m) {  return iconv('ucs-2', 'utf-8', pack('H*', $m[1]));}
Copy after login
["中文",["中文"]]

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!