PHP json_encode() Emoji 图标和字母作为数组键值

Sam*_*ami 0 php

我有一个数组,其中表情符号图标和文本字符串作为键值,类似于以下内容:

$a=array(
   " hi no 1"=> "  this is a test",
   " hi no 1"=> "  this is a test",
   " hi no 1"=> "  this is a test",
   " hi no 1"=> "  this is a test",
    " no 3" => array("this is a test"," test"),
    " no 3" => array("this is a test"," test"),
    " no 3" => array("this is a test"," test"),
    " no 3" => array("this is a test"," test"),
    " no 3" => array("this is a test"," test"),
);
Run Code Online (Sandbox Code Playgroud)

问题在于file_put_contents($filepath,json_encode($a));将空数组保存到数据库中。您会建议一个解决方案吗?

dav*_*ave 6

你可以尝试

file_put_contents($filepath,json_encode($a, JSON_UNESCAPED_UNICODE));
Run Code Online (Sandbox Code Playgroud)

看看这是否有效,因为表情符号是 unicode 我认为这可以解决它。