如何将包含国际字符的 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>
json utf8 编码和解码:
json_encode($data, JSON_UNESCAPED_UNICODE)
json_decode($json, false, 512, JSON_UNESCAPED_UNICODE)
强制 utf 8 也可能有帮助:http://pastebin.com/2XKqYU49 http://pastebin.com/2XKqYU49
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)