UTF-8 字符串在某处编码错误
我有一个列 title
,其格式为 CHAR(50) utf_genral_ci。我有一个 php 脚本,可以成功插入 title
值“Bjørn”的新行。
当我想再次拔出它时,问题就出现了。一旦它被分配给一个变量,字符串就是“Bjärn”。
有些人向我指出 mb_*() ,但是,因为当我从表单检索它并插入它时这不是问题,但只有当我从 mysql 检索它时,我不相信会是这样。
我已经确保它实际上在 mysql 中正确编码,并且服务器、数据库、表、列和连接都是 UTF-8。
请有人救我脱离这场噩梦!
提前致谢
I have a column, title
, which is of the format CHAR(50) utf_genral_ci. I have a php script that successfully inserts a new row with the title
value "Bjørn".
The problem occurs when I want to pull it out again. Once it is assigned to a variable the string is "Bjørn".
Some have pointed me towards mb_*(), however since it's not a problem when I am retrieving it from a form and inserting it, but only when I retrieve it from mysql, I dont believe that can be it.
I have made sure that it is in fact encoded correctly in mysql, and server, database, table, column and connection are ALL UTF-8.
Please someone save me from this nightmare!
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
原来是因为我在字符串上使用了 php 函数 htmlentities() 。自从我上次尝试以来非常奇怪,它也直接从数据库输出错误。
我一整天都遇到这个问题,所以一个问题的解决方案引发了另一个问题。
感谢您抽出宝贵时间。
It turned out to be because I used the php function htmlentities() on my string. Very weird since last I tried, it also output wrong straight from the database.
I have been having problems with this all day, so the solution to one problem has caused another.
Thanks for taking your time.
您是否使用 phpMyAdmin 或 MySQL Workbench 等管理工具检查数据库中的值?如果显示不正确,请尝试使用 iconv ($in_charset, 'utf-8', $str) 将名称转换为 utf-8。如果正确,请确保浏览器中的编码设置为 UTF-8。
Did you check the value in database using an admin tool like phpMyAdmin or MySQL Workbench? If it is not displayed correctly, try converting the name to utf-8 using
iconv ($in_charset, 'utf-8', $str)
. If it is correct, make sure that the encoding in your browser is set to UTF-8.