Creating a UTF-8 string from hexadecimal code

laurent picture laurent · Apr 19, 2013 · Viewed 9.2k times · Source

In C++, it's possible create a UTF-8 string using this kind of notation: "\uD840\uDC50".

However this doesn't work in PHP. Is there a similar notation?

If not, is there any built-in way to create a UTF-8 string knowing its Unicode code point?

Answer

laurent picture laurent · Apr 19, 2013

I've ended up implementing it like this:

$utf8 = html_entity_decode("一", ENT_COMPAT, 'UTF-8');