问题描述
当我从我的数据库中获取一条记录时,其中的数据库、表和行都设置为 utf8_unicode_ci
,我收到一个用对角线方块框起来的问题,而不是正确的 unicode特点;尽管我还在页面上设置了 HTML 编码:
When I fetch a record from my database, where the database, the table, and the row are all set to utf8_unicode_ci
, I recieve a question boxed in a diagonal square in place of the correct unicode character; this is despite me also setting the HTML encoding on the page with:
<meta charset="utf8">
我有一个怀疑,但是它与 MySQL/PHP 有关,因为当我 print_r
输出时,问号仍在显示,而手动输入的度数符号(我应该看到的符号)工作良好.
I have a suspicion however it is to do with MySQL/PHP though because when I print_r
the output the question marks are still displaying while a manually entered degree symbol (the symbol I should be seeing) works fine.
这个 SQL 查询也没有做任何事情:
This SQL query also did nothing:
SET NAMES utf8;
有什么想法吗?我已经检查了我设置的每一端.
Any ideas? I've checked every end of my setup.
推荐答案
utf8_unicode_ci
是排序规则,需要字符集为 utf8
为例:
utf8_unicode_ci
is the collation, you need the character set as utf8
as example:
CREATE TABLE someTable DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci;
正如 adrienne 在此处的回答中所述:
As adrienne states in their answer here:
确保以下所有内容均属实:
- 数据库连接使用的是 UTF-8
- 数据库表使用的是 UTF-8
- 数据库表中的各个列使用的是 UTF-8
- 数据实际上存储在数据库内的 UTF-8 编码中(如果您从错误的来源导入,通常情况并非如此,或更改表或列排序规则)
- 网页正在请求 UTF-8
- Apache 正在服务 UTF-8
- 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
这篇关于尽管字符集和排序规则正确,网页仍输出问号代替 unicode 字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!