当我从我的数据库中获取记录时,数据库、表和行都设置为 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/