Unicode codepoint escape syntax

Viewed 567

I'm trying to use "Unicode codepoint escape syntax" to display emoji by its unicode.

The basic syntax is:

echo "\u{1f606}"; - And it works fine

However when i insert the unicode from variable:

$unicode = "1f606";
echo "\u{".$unicode."}";

I get «Invalid UTF-8 codepoint escape sequence» error.

1 Answers

You cannot use "\u{}" notation for conversion, use mb_chr() instead.

Example:

$unicode= 0x1f606;
echo mb_chr($unicode);
Related