-3

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).

  • There are quite some useful tips here: https://stackoverflow.com/questions/643694/what-is-the-difference-between-utf-8-and-unicode Can you solve your problem now? If not, then please tell use exactly where your are stuck. – KIKO Software Oct 20 '22 at 15:31

1 Answers1

1

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"
jspit
  • 7,276
  • 1
  • 9
  • 17