PHP/MySQL特殊字符显示不正确 [英] PHP/MySQL Special Characters aren't displayed properly
问题描述
可能重复:
PHP/MySQL中的特殊字符
Possible Duplicate:
Special characters in PHP / MySQL
我有问题.我的数据库(MySQL 5.5.20)中有一段文本,其中包含'é'和'等字符,这些字符在执行MySQL查询并用echo($ ...)显示后无法正确显示.我在数据库中输入的每个特殊字符都会在菱形内显示一个小问号.如果我查看数据库本身中的文本,它是一个'é'和'",因此我认为问题不是MySQL.
I have a problem. I have a piece of text in my database (MySQL 5.5.20) with characters like 'é' and " ' " who aren't displaying properly after executing the MySQL query and displaying it with echo($...). With every special character I've inputted in the database, it displays a small question mark inside a diamond. If I look at the text in the database itself, it is an 'é' and " ' ", so I figured the problem isn't MySQL.
我可以做的一件事就是在输入中str_replace像'"->'"之类的所有东西,但是然后我必须对存在的每个字符都这样做. 哦,我已经包含了
One thing I could do is str_replace everything like " ' " --> "'" on input, but then I have to do this for every character there is. Oh and I already have included
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
,这不起作用.
希望您能获得所有的信息,对我有帮助,即使不只是说:)在此先感谢您!
Hopefully you've all the information to help me, if not just say :) Thanks in advance!
米兰来语
推荐答案
您需要将所有内容都保存在utf-8中:
You need to have everything in utf-8:
- 数据库字段
- 数据库连接(在经典mysql中为
mysql_set_charset('utf8');
,在PDO中类似$db->exec('SET CHARACTER SET utf8');
) - 内容类型(就像您已经拥有的一样)
- The database field
- The database connection (
mysql_set_charset('utf8');
in classic mysql, something like$db->exec('SET CHARACTER SET utf8');
in PDO) - The content type (like you have already)
这篇关于PHP/MySQL特殊字符显示不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!