UTF-8 问题 PHP/MySQL [英] UTF-8 problems PHP/MySQL

查看:30
本文介绍了UTF-8 问题 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/en/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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆