PHP的json_encode中的西里尔字符 [英] Cyrillic characters in PHP's json_encode
本文介绍了PHP的json_encode中的西里尔字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用php函数json_encode将西里尔UTF-8数组编码为JSON字符串.示例代码如下:
I'm trying to encode Cyrillic UTF-8 array to JSON string using php's function json_encode. The sample code looks like this:
<?php
$arr = array(
'едно' => 'първи',
'две' => 'втори'
);
$str = json_encode($arr);
echo $str;
?>
它工作正常,但脚本的结果表示为:
It works fine but the result of the script is represented as:
{"\u0435\u0434\u043d\u043e":"\u043f\u044a\u0440\u0432\u0438","\u0434\u0432\u0435":"\u0432\u0442\u043e\u0440\u0438"}
,每个西里尔字母组成6个字符.有没有办法获取键/值对的原始字符而不是编码的对字符?
which makes 6 characters for each Cyrillic character. Is there a way to get the original characters for key/value pairs instead of encoded ones?
推荐答案
您不能使用 JSON_UNESCAPED_UNICODE 在这里恒定吗?
Can't you use JSON_UNESCAPED_UNICODE constant here?
这篇关于PHP的json_encode中的西里尔字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文