Platon Platon - 1 year ago 283
PHP Question

How to convert Emoji from Unicode in PHP?

I use this table of Emoji and try this code:

<?php print json_decode('"\u2600"'); // This convert to ☀ (black sun with rays) ?>

If I try to convert this \u1F600 (grinning face) through
, I see this symbol —

Whats wrong? How to get right Emoji?

Answer Source


JSON's \u can only handle one UTF-16 code unit at a time, so you need to write the surrogate pair instead. For U+1F600 this is \uD83D\uDE00, which works:

echo json_decode('"\uD83D\uDE00"');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download