Reputation: 85
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.
Upvotes: 2
Views: 10521
Reputation: 85
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
Upvotes: 4
Reputation: 302
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
Upvotes: 0