php 带有选项 JSON_UNESCAPED_UNICODE 的 json_encode
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9801533/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
json_encode with option JSON_UNESCAPED_UNICODE
提问by Ben
When using echo json_encode($array, JSON_UNESCAPED_UNICODE);
当使用 echo json_encode($array, JSON_UNESCAPED_UNICODE);
I get the this error
我得到这个错误
Warning: json_encode() expects exactly 1 parameter, 2 given
警告:json_encode() 需要 1 个参数,2 个给定
回答by biziclop
Your php version might be too low:
您的 php 版本可能太低:
http://php.net/manual/en/function.json-encode.php
http://php.net/manual/en/function.json-encode.php
string json_encode ( mixed $value [, int $options = 0 ] )
5.3.0 The options parameter was added
回答by pevik
See patch at http://code.google.com/p/apns-php/issues/detail?id=22which allows the same functionality on PHP 5.2.
请参阅http://code.google.com/p/apns-php/issues/detail?id=22上的补丁,它允许在 PHP 5.2 上使用相同的功能。
Basically run something like this:
基本上运行这样的:
foreach ($array as &$val) {
$val = preg_replace_callback('/\\u([0-9a-f]{4})/i',
function($matches) {
return mb_convert_encoding(pack('H*', $matches[1]), 'UTF-8', 'UTF-16');
}, $val);
}