I want to convert the emoji code i.e, ":)" to ๐.
How can I convert it?
Currently I am using p3k detector to detect the emoji's. Below is the code where I can detect the emoji's.
$emoji = \Emoji\detect_emoji($text);
Join Stack Overflow to learn, share knowledge, and build your career.
I want to convert the emoji code i.e, ":)" to ๐.
How can I convert it?
Currently I am using p3k detector to detect the emoji's. Below is the code where I can detect the emoji's.
$emoji = \Emoji\detect_emoji($text);
You need to create your own function to convert (or search online if there is any library that already do this).
function stringToEmoji($str) {
$emojis = [
'o/' => '๐',
'</3' => '๐',
'<3' => '๐',
'8-D' => '๐',
'8D' => '๐',
':-D' => '๐',
'=-3' => '๐',
'=-D' => '๐',
'=3' => '๐',
'=D' => '๐',
'B^D' => '๐',
'X-D' => '๐',
'XD' => '๐',
'x-D' => '๐',
'xD' => '๐',
':\')' => '๐',
':\'-)' => '๐',
':-))' => '๐',
'8)' => '๐',
':)' => '๐',
':-)' => '๐',
':3' => '๐',
':D' => '๐',
':]' => '๐',
':^)' => '๐',
':c)' => '๐',
':o)' => '๐',
':}' => '๐',
':ใฃ)' => '๐',
'=)' => '๐',
'=]' => '๐',
'0:)' => '๐',
'0:-)' => '๐',
'0:-3' => '๐',
'0:3' => '๐',
'0;^)' => '๐',
'O:-)' => '๐',
'3:)' => '๐',
'3:-)' => '๐',
'}:)' => '๐',
'}:-)' => '๐',
'*)' => '๐',
'*-)' => '๐',
':-,' => '๐',
';)' => '๐',
';-)' => '๐',
';-]' => '๐',
';D' => '๐',
';]' => '๐',
';^)' => '๐',
':-|' => '๐',
':|' => '๐',
':(' => '๐',
':-(' => '๐',
':-<' => '๐',
':-[' => '๐',
':-c' => '๐',
':<' => '๐',
':[' => '๐',
':c' => '๐',
':{' => '๐',
':ใฃC' => '๐',
'%)' => '๐',
'%-)' => '๐',
':-P' => '๐',
':-b' => '๐',
':-p' => '๐',
':-ร' => '๐',
':-รพ' => '๐',
':P' => '๐',
':b' => '๐',
':p' => '๐',
':ร' => '๐',
':รพ' => '๐',
';(' => '๐',
'=p' => '๐',
'X-P' => '๐',
'XP' => '๐',
'd:' => '๐',
'x-p' => '๐',
'xp' => '๐',
':-||' => '๐ ',
':@' => '๐ ',
':-.' => '๐ก',
':-/' => '๐ก',
':/' => '๐ก',
':L' => '๐ก',
':S' => '๐ก',
':\\' => '๐ก',
'=/' => '๐ก',
'=L' => '๐ก',
'=\\' => '๐ก',
':\'(' => '๐ข',
':\'-(' => '๐ข',
'^5' => '๐ค',
'^<_<' => '๐ค',
'o/\\o' => '๐ค',
'|-O' => '๐ซ',
'|;-)' => '๐ซ',
':###..' => '๐ฐ',
':-###..' => '๐ฐ',
'D-\':' => '๐ฑ',
'D8' => '๐ฑ',
'D:' => '๐ฑ',
'D:<' => '๐ฑ',
'D;' => '๐ฑ',
'D=' => '๐ฑ',
'DX' => '๐ฑ',
'v.v' => '๐ฑ',
'8-0' => '๐ฒ',
':-O' => '๐ฒ',
':-o' => '๐ฒ',
':O' => '๐ฒ',
':o' => '๐ฒ',
'O-O' => '๐ฒ',
'O_O' => '๐ฒ',
'O_o' => '๐ฒ',
'o-o' => '๐ฒ',
'o_O' => '๐ฒ',
'o_o' => '๐ฒ',
':$' => '๐ณ',
'#-)' => '๐ต',
':#' => '๐ถ',
':&' => '๐ถ',
':-#' => '๐ถ',
':-&' => '๐ถ',
':-X' => '๐ถ',
':X' => '๐ถ',
':-J' => '๐ผ',
':*' => '๐ฝ',
':^*' => '๐ฝ',
'เฒ _เฒ ' => '๐
',
'*\\0/*' => '๐',
'\\o/' => '๐',
':>' => '๐',
'>.<' => '๐ก',
'>:(' => '๐ ',
'>:)' => '๐',
'>:-)' => '๐',
'>:/' => '๐ก',
'>:O' => '๐ฒ',
'>:P' => '๐',
'>:[' => '๐',
'>:\\' => '๐ก',
'>;)' => '๐',
'>_>^' => '๐ค',
];
if(isset($emojis[$str])) {
return $emojis[$str];
}
return null;
}
echo stringToEmoji(':)');
Output:
๐
Got list from this answer: https://stackoverflow.com/a/29581503/1580044
I cannot insert the whole function here because it bypasses stack overflow characters limit. Here's the link to it:
https://gist.github.com/BarryMode/432a7a1f9621e824c8a3a23084a50f60#file-htmlemoji-php
Shortly, the function is
preg_replace_callback(pattern, callback, string);
Where the string is the input where you have emoji that you want to change into html entities. The pattern uses regex to find the emoji in the string and then each one is fed into the callback, which is where the conversion happens from emoji to html entity.