doumaojin4008 2012-08-08 01:13
浏览 37
已采纳

正确处理外来字符/表情符号

Having trouble getting foreign characters and Emoji to display.

Edited to clarify

A user types an Emoji character into a text field which is then sent to the server (php) and saved into the database (mysql). When displaying the text we grab a JSON encoded string from the server, which is parsed and displayed on the client side.

QUESTION: the character for a "trophy" emoji saved in the DB reads as

%uD83C%uDFC6

When that is sent back to the client we don't see the emoji picture, we actually see the raw encoded text.

How would we get the client side to read that text as an emoji character and display the image?

(all on an iphone / mobile safari)

Thanks!

  • 写回答

3条回答 默认 最新

  • dongtangu8403 2012-08-10 11:17
    关注

    the character for a "trophy" emoji saved in the DB reads as %uD83C%uDFC6

    Then your data are already mangled. %u escapes are specific to the JavaScript escape() function, which should generally never be used. Make sure your textarea->PHP handling uses standards-compliant encoding, eg encodeURIComponent if you need to get a JS variable into a URL query.

    Then, having proper raw UTF-8 strings in your PHP layer, you can worry about getting MySQL to store characters like the emoji that are outside of the Basic Multilingual Plane. Best way is columns with a utf8mb4 collation; if that is not available try binary columns which will allow you to store any byte sequence (treating it as UTF-8 when it comes back out). That way, however, you won't get case-insensitive comparisons.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题