Home Β» Php Β» php – Convert to full unicode string

php – Convert to full unicode string

Posted by: admin February 25, 2020 Leave a comment

Questions:

How can I convert a string from \uD83D\uDE00 to full \U0001f603?
json_encode() only converts to the first option…

$str = 'πŸ˜ƒ';
$encode = json_encode($str);
var_dump($encode);

// string(14) ""\ud83d\ude03""
How to&Answers:

Assuming you have the Intl extension installed, this is easy enough to do with one of its built-in transliterators:

<?php
$str = "πŸ˜€";
echo transliterator_create("Any-Hex/C")->transliterate($str);

Output:

\U0001F603