如何存储像♥☆这样的字符到数据库?
Previous issue - was not able to store non-english characters:
How to store non-english characters?
That was fixed by using UTF8. But realized today that symbols like ♥☆
are not stored correctly. They get converted to characters like ♥☆
.
How can this be fixed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,它们的存储是正确的,但是当您读出它们时,您没有正确地解释它们。
♥
和☆
最终将成为 UTF-8 编码中的多字节字符。我敢打赌,如果您查找该多字节编码,您会发现它分别与♥
和†
的单字节编码相同。编辑:添加细节。
如下表所示,将 UTF-8 字符解释为如同 Windows Latin-1 编码一样,可以得到您所看到的结果。
It looks to me like they're being stored correctly, but that you're not interpreting them correctly when you read them out.
♥
and☆
are going to end up as multibyte characters in UTF-8 encoding. I'll bet if you look up that multibyte encoding, you'll see it's the same as the single-byte encoding for♥
and☆
respectively.Edit: adding details.
As you can see in the following table, interpreting the UTF-8 characters as if they were encoded as Windows Latin-1 gives the results you're seeing.
UTF8 是否在整个范围内一致使用(MySQL、PHP、Apache、
、标头......)?对我来说,这是开箱即用的:
调试输出:
Is UTF8 used consistently across the whole spectrum (MySQL, PHP, Apache, <meta>s, headers..)?
For me this worked out of the box:
Debug output: