Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert emoji to their hex code

I'm trying to detect the emoji that I get through e.g. a POST (the source ist not necessary).

As an example I'm using this emoji: ✊🏾 (I hope it's visible)

The code for it is U+270A U+1F3FE (I'm using http://unicode.org/emoji/charts/full-emoji-list.html for the codes)

Now I converted the emoji with json_encode and I get: \u270a\ud83c\udffe

Here the only part that is equal is 270a. \ud83c\udffe is not equal to U+1F3FE, not even if I add them together (1B83A)

How do I get from ✊🏾 to U+270A U+1F3FE with e.g. php?

like image 487
Mr.Tr33 Avatar asked Nov 13 '16 15:11

Mr.Tr33


1 Answers

You can do like this, consider the emoji a normal character.

$emoji = "✊🏾";

$str = str_replace('"', "", json_encode($emoji, JSON_HEX_APOS));

$myInput = $str;

$myHexString = str_replace('\\u', '', $myInput);
$myBinString = hex2bin($myHexString);

print iconv("UTF-16BE", "UTF-8", $myBinString); 
like image 105
Vinny Avatar answered Oct 22 '22 15:10

Vinny