I use the below code to convert an emoji to unicode, but how do i apply this to a string without affecting the other text in string.
function emoji_to_unicode($emoji) {
$emoji = mb_convert_encoding($emoji, 'UTF-32', 'UTF-8');
$unicode = strtoupper(preg_replace("/^[0]+/","U+",bin2hex($emoji)));
return $unicode;
}
$var = "";
echo emoji_to_unicode($var);
If $var
is hello , goodbye
then the output is U+68000000650000006C0000006C0000006F000000200001F6000000002C00000020000000670000006F0000006F00000064000000620000007900000065
When it should be hello U+1F600, goodbye