UTF-8 problems PHP/MySQL(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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UTF-8 问题 PHP/MySQL
- PHP foreach() 与数组中的数组? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01