skip to Main Content

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.
“u263aud83dude00ud83dude01ud83dude02ud83dude03” (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.

2

Answers


  1. Chosen as BEST ANSWER

    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 = "u263aud83dude00ud83dude01ud83dude02ud83dude03";
    echo decodeEmoticons($src);
    

    it will shows you the emojis icons


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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search