How to convert Unicode codepoint to UTF-8 Hex Bytes?

610 views Asked by At

Given a list of all emojis, I need to convert unicode codepoint to UTF-8 hex bytes programmatically.

For example:

Take this emoji: https://unicode-table.com/en/1F606/ and convert 1F606 to F0 9F 98 86

Please provide code examples in python or hacklang (php).

1

There are 1 answers

0
jspit On

If you want to know how to notate a Unicode character like U+1F606 in PHP, then do this:

$myChar = "\u{1F606}";

You must write it down like this and not make it up from substrings.

If you have '1F606' as a character string, you must convert it.

$code = "1F606";

$myChar = html_entity_decode('&#x'.$code.";", ENT_QUOTES, 'UTF-8');

Demo: https://3v4l.org/312KC

Variant 3: You can also write the emjois directly into your code.

$myChar = "";

The bin2hex function supplies the individual hexadecimal bytes.

$hex = bin2hex($myChar);  //"f09f9886"