問題描述
我一直使用 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!