【发布时间】:2011-05-03 21:10:47
【问题描述】:
如何将带有国际字符的 json 编码字符串保存到数据库中,然后在浏览器中解析解码后的字符串?
<?php
$string = "très agréable";
// to the database
$j_encoded = json_encode(utf8_encode($string));
// get from Database
$j_decoded = json_decode($j_encoded);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<?= $j_decoded ?>
</html>
【问题讨论】:
-
和你展示的差不多。什么不起作用?
-
它给了我:très agréable
-
尝试将页面的字符集设置为 UTF-8... 在 块
-
@Mark,这有效,但仅在使用 $j_encoded = json_encode($string);所以没有 utf8_encode()
-
@FFish 去掉你代码中的
utf8_encode(),我刚刚看到了(编辑:啊,你更快)