简体   繁体   中英

PHP json_encode() Emoji icons and letters as an array key value

I have an array which has Emoji icons and text strings as the key value, similar to below:

$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"),
);

The problem is that file_put_contents($filepath,json_encode($a)); saves an empty array into the database. Would you suggest a solution?

You could try

file_put_contents($filepath,json_encode($a, JSON_UNESCAPED_UNICODE));

And see if that works, since emoji are unicode I would think that would solve it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM