UTF-8问题PHP/MySQL [英] UTF-8 problems PHP/MySQL
问题描述
我一直使用ISO-8859-1编码,但是现在我要使用UTF-8.
I've always used ISO-8859-1 encoding, but I'm now going over to UTF-8.
不幸的是我无法正常工作.
Unfortunately I can't get it to work.
我的MySQL数据库是UTF-8,我的PHP文档是用UTF-8编码的,我设置了UTF-8字符集,但仍然无法正常工作.
My MySQL DB is UTF-8, my PHP document is encoded in UTF-8, I set a UTF-8 charset, but it still doesn't work.
(像æ/ø/å这样的特殊字符不起作用)
(it is special characters like æ/ø/å that doesn't work)
希望你们能提供帮助!
推荐答案
确保与数据库的连接也使用此字符集:
Make sure the connection to your database is also using this character set:
$conn = mysql_connect($server, $username, $password);
mysql_set_charset("UTF8", $conn);
根据php.net中mysql_set_charset
的文档:
According to the documentation of mysql_set_charset
at php.net:
Note:
This is the preferred way to change the charset. Using mysql_query() to execute
SET NAMES .. is not recommended.
另请参见: http://nl3.php.net /manual/en/function.mysql-set-charset.php
使用以下方法检查当前连接的字符集:
Check the character set of your current connection with:
echo mysql_client_encoding($conn);
另请参见: http://nl3.php.net /manual/zh-CN/function.mysql-client-encoding.php
如果您已完成上述操作并将奇怪的字符添加到表中,您将看到它显示正确.
If you have done these things and add weird characters to your table, you will see it is displayed correct.
这篇关于UTF-8问题PHP/MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!