一些字符会变成“。”。在我们的网页上 [英] Some characters become "�" in our webpage
问题描述
我使用PHP访问数据库以获取这样的字符串
I use PHP to access a database to get a string like this
Chloe时装秀&晚餐
‘Chloe’ Fashion Show & Dinner
然后我执行printf()将字符串输出为html,但是我的网页显示了这一点:
and then I do a printf() to output the string as html, but my webpage shows this:
Chloe.Fashion Show&晚餐
�Chloe� Fashion Show & Dinner
所有内容均基于英语,我想念PHP吗?
All contents are English-based, do I miss something in PHP?
我应该在哪里检查?
推荐答案
- 检查您的.php文件是否编码为不带BOM的UTF-8
- 检查与数据库的连接是否为UTF-8
- 检查是否发送
< meta charset = utf-8>
在HTML标记中的< head>
标记
- Check if your .php file is encoded as UTF-8 without BOM
- Check that your connection to the database is UTF-8
- Check that you send
<meta charset="utf-8">
in your HTML markup in the<head>
tag
如果您与数据库的连接不是UTF-8,并且您不想更改它(但我建议它->一切都是UTF -8是针对字符垃圾的最安全的解决方案),请使用 utf8_encode ($ databaseValue)
以确保您的值的编码为UTF-8。
If your connection to the database is not UTF-8 and you don't want to change it (but I recommend it -> everything UTF-8 is the most secure solution against character rubbish) use utf8_encode($databaseValue)
to ensure the encoding of your value is UTF-8.
这篇关于一些字符会变成“。”。在我们的网页上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!