Any way to return PHP `json_encode` with encode UTF-8 and not Unicode?(有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`?)
问题描述
有没有办法用编码 UTF-8 而不是 Unicode 返回 PHP json_encode
?
Any way to return PHP json_encode
with encode UTF-8 and not Unicode?
$arr=array('a'=>'á');
echo json_encode($arr);
mb_internal_encoding('UTF-8');
和 $arr=array_map('utf8_encode',$arr);
没有修复它.
结果:{"a":"u00e1"}
预期结果:{"a":"á"}
推荐答案
{"a":"u00e1"}
and {"a":"á"}
是编写相同 JSON 文档的不同方式;JSON 解码器将解码 unicode 转义.
{"a":"u00e1"}
and {"a":"á"}
are different ways to write the same JSON document; The JSON decoder will decode the unicode escape.
在 php 5.4+ 中,php 的 json_encode
确实有用于纯输出的 JSON_UNESCAPED_UNICODE
选项.在较旧的 php 版本上,您可以推出自己的不编码非 ASCII 字符的 JSON 编码器,或使用 Pear 的 JSON 编码器并删除第 349 到 433 行.
In php 5.4+, php's json_encode
does have the JSON_UNESCAPED_UNICODE
option for plain output. On older php versions, you can roll out your own JSON encoder that does not encode non-ASCII characters, or use Pear's JSON encoder and remove line 349 to 433.
这篇关于有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`?


- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01