1 php json utf-8 character-encoding
我在mysql数据库中存储了一个包含一些(中文?)字符的json字符串.数据库中的内容示例:
normal.text.\u8bf1\u60d1.rest.of.text
Run Code Online (Sandbox Code Playgroud)
在我的PHP页面上,我只是对从mysql收到的json_decode做了一个json_decode,但它显示不正确,它显示的内容如"½±è§ "
我试图在我的文件开头执行"SET NAMES'utf8'"查询,没有改变任何东西.我的网页上已经有以下标题:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Run Code Online (Sandbox Code Playgroud)
当然我所有的php文件都是用UTF-8编码的.
你知道如何很好地显示这些"\ uXXXX"字符吗?
这对我来说似乎很好,在Ubuntu 11.04上使用PHP 5.3.5:
<?php
header('Content-Type: text/plain; charset="UTF-8"');
$json = '[ "normal.text.\u8bf1\u60d1.rest.of.text" ]';
$decoded = json_decode($json, true);
var_dump($decoded);
Run Code Online (Sandbox Code Playgroud)
输出:
array(1) {
[0]=>
string(31) "normal.text.??.rest.of.text"
}
Run Code Online (Sandbox Code Playgroud)