php - 尽管字符集和排序规则正确,但网页输出问号而不是 unicode 字符?

标签 php mysql unicode

当我从我的数据库中获取记录时,数据库、表和行都设置为 utf8_unicode_ci,我收到一个用对角方框框起来的问题,而不是正确的 unicode特点;尽管我还在页面上设置了 HTML 编码:

 <meta charset="utf8">

我怀疑这与 MySQL/PHP 有关,因为当我 print_r 输出时,问号仍在显示,而手动输入的度数符号(我应该看到的符号)工作正常。

此 SQL 查询也没有执行任何操作:

SET NAMES utf8;

有什么想法吗?我检查了设置的每一端。

最佳答案

utf8_unicode_ci 是排序规则,你需要字符集为 utf8 例如:

CREATE TABLE someTable DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci;

正如 adrienne 在 their answer here 中所说的那样:

make sure that all of the following are true:

  • The DB connection is using UTF-8
  • The DB tables are using UTF-8
  • The individual columns in the DB tables are using UTF-8
  • The data is actually stored properly in the UTF-8 encoding inside the database (often not the case if you've imported from bad sources, or changed table or column collations)
  • The web page is requesting UTF-8
  • Apache is serving UTF-8

关于php - 尽管字符集和排序规则正确,但网页输出问号而不是 unicode 字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20823367/

相关文章:

php - 如何在不知道文件扩展名的情况下按其名称取消链接()?

mysql - Go Template 循环(范围)出评论

java - 从文本文件 :  读取的第一个字符

mysql - 检查时间戳列值是否超过六个月

scheduled-tasks - 为什么我必须提供帐户信息才能通过 Windows 7 中的计划任务运行 mysqldump.exe

python - 遍历unicode字符串并与python字典中的unicode进行比较

unicode - 6 个八位字节的 UTF-8 序列是否有效?

php - 使用 GA、jQuery 和 PHP 跟踪文件下载

javascript - $.get jquery 函数返回完整的 html 页面而不是数据中的 json

php - 导致 Codeigniter Controller 的子域?