是否可以再次将表情符号 3 或 4 字节字符串重新编码为表情符号?
我继承了一个 utf8_unicode_ci 编码的 MySQL Innodb 表。这些表情符号 4 字节字符串无处不在。是否可以将它们翻译回表情符号?
第一步是将字符集
修改为utf8mb4
。这将像 ð����£
这样的所有字符串更改为像这样的字符串:ðŸ∼Š
。
但我真正想要的是将 ðŸ∼Š
翻译成类似 的内容. (我不知道 ðŸ∼Š
是否真的是笑脸)
最佳答案
灵感来自 Ignacio Vazquez-Abrams' comment .下一个 python 代码片段显示了原始过程 Emoji至 Mojibake反之亦然(修复):
print ( "\nEmoji to mojibake (origin):")
for emojiChar in ['😊','😣','👽','😎']:
print ( emojiChar, emojiChar.encode('utf8').decode('cp1252'))
print ( "\nmojibake to Emoji (repair):")
for mojibakeString in ['😊','😣','👽','😎','🙇']:
print ( mojibakeString, mojibakeString.encode('cp1252').decode('utf8'))
我知道这个问题被标记为php而不是 python;让我希望类似的 php 解决方案可以非常接近......
输出:
==> chcp 65001
Active code page: 65001
==> D:\test\Python\20108312.py
Emoji to mojibake (origin):
😊 😊
😣 😣
👽 👽
😎 😎
mojibake to Emoji (repair):
😊 😊
😣 😣
👽 👽
😎 😎
🙇 🙇
==>
Python 版本:
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32
关于php - 如何恢复存储在普通 utf8 中的 4 字节表情符号字符的正确编码 - 就像这样 : 😊?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20108312/