2

I have setup a twiml app in twillio which forward/post all sms (which came to my twillio number) to a domain . On that domain i can get message body.issue is when some one send emojis in SMS . for this i did json_encode($sms->body); which show me emojis like this. "\u263a\ud83d\ude00\ud83d\ude01\ud83d\ude02\ud83d\ude03" (these are some emojis which came through SMS)

i did json_decode() as well for above text but it not shows me correct emojis icons. it shows like this (☺😀ðŸ˜ðŸ˜‚😃)

Which encoding or decoding i should use please help me.

waleed.mirza
  • 85
  • 1
  • 8
  • 1
    Possible duplicate of [How to convert Emoji from Unicode in PHP?](http://stackoverflow.com/questions/33547233/how-to-convert-emoji-from-unicode-in-php) – Mihai Matei May 24 '16 at 10:42
  • @MateiMihai sir i try the above as well but not helpful . if we write echo json_decode('"\uD83D\uDE00"'); in php file it won't show smiley face i try it in chrome/firefox but noting happens. – waleed.mirza May 24 '16 at 11:19
  • I think depends on the font used.. the font should support those emoji – Mihai Matei May 24 '16 at 11:36

2 Answers2

4

You just need to follow these steps 1. make sure you have set header("Content-Type: text/html; charset=utf-8"); 2. use this method

function decodeEmoticons($src) {
    $replaced = preg_replace("/\\\\u([0-9A-F]{1,4})/i", "&#x$1;", $src);
    $result = mb_convert_encoding($replaced, "UTF-16", "HTML-ENTITIES");
    $result = mb_convert_encoding($result, 'utf-8', 'utf-16');
    return $result;
}
$src = "\u263a\ud83d\ude00\ud83d\ude01\ud83d\ude02\ud83d\ude03";
echo decodeEmoticons($src);

it will shows you the emojis icons

waleed.mirza
  • 85
  • 1
  • 8
0

See first of all check in your database Collation and set utf8_general_ci after that check your table Collation and set utf8_unicode_ci OR utf8_general_ci

Gorakh Yadav
  • 304
  • 5
  • 19