-1

I have emotions in javascript escaped characters in a string and need to pass it to Android as json. In the android side the text has to be utf8 to display the emotion character properly. For example I have \ud83d\ude00 in a string which is a code for GRINNING FACE. But I need it to be converted to f0 9f 98 80 using Php.

I tried mb_convert_encoding and iconv but they outputs some strange characters. Please help. Thanks

Vasanthan.R.P
  • 1,277
  • 1
  • 19
  • 46
  • Possible duplicate of [How to decode Unicode escape sequences like "\u00ed" to proper UTF-8 encoded characters?](http://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-cha) – Karolis Mar 03 '16 at 12:22
  • Do you have ***JSON***? If you decode that JSON, the characters should come out as is. If not JSON, does that mean you literally just have `$str = '\ud83d\ude00';`...? Then my question would be: how did you end up with that in the first place? – deceze Mar 03 '16 at 12:25
  • deceze Actually I have these data in the mysql db and I can print them on the website using json_decode and it displays the smiley correctly. But I send the data through api for Android and it needs to be converted to the corresponding utf8 character. Please advise. – Vasanthan.R.P Mar 04 '16 at 05:36

1 Answers1

1

Seems like a duplicate of:

How to decode Unicode escape sequences like "\u00ed" to proper UTF-8 encoded characters?

$str = preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/', function ($match) {
    return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}, $str);
Community
  • 1
  • 1
Karolis
  • 2,580
  • 2
  • 16
  • 31