Emoji to JSON encoded, post to web server

陌路散爱 提交于 2019-12-03 08:42:10

Once the data is sent to your php script you need to convert it to a multibyte string:

$content = mb_convert_encoding($content, 'UTF-8');

You can use this function:

function cb($content){

  if(!mb_check_encoding($content, 'UTF-8')
   OR !($content === mb_convert_encoding(mb_convert_encoding($content, 'UTF-32', 'UTF-8' ), 'UTF-8', 'UTF-32'))) {

    $content = mb_convert_encoding($content, 'UTF-8');

  }
  return $content;
}

Edit: The data was probably of type application/x-www-form-urlencoded for us and that function converted it correctly.

emoji characters are most likely transcoded in UNICODE, so it should be sufficient to just send, receive and manage your data in UTF-8.

When receiving with this

$postData = file_get_contents("php://input") 

(I suppose that is a real URL), make sure your php script sends an Content-Encoding header (like the following, choose a MIME-type that suits you)

 header("Content-Type: text/html; charset=utf-8");

Please follow following steps:

  • Convert Emoji characters to base64 and send to server.
  • On server side save base64 in database without decode.
  • When you want to display Emoji on Application then retrieve same base64 data from server.
  • Decode retrieve string and display on app.
  • Your Emoji character will display properly.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!