0

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""
miken32
  • 42,008
  • 16
  • 111
  • 154
  • I'm not sure there's a built in function for that, so you should roll your own, maybe using preg_replace_callback.. However, what is the use case here? You mention JSON, but JSON can't use the `\U` syntax. – Mr Lister Feb 12 '20 at 12:06

1 Answers1

0

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
miken32
  • 42,008
  • 16
  • 111
  • 154