P粉8541192632023-08-28 11:11:30
我想在 chazomaticus 的出色答案中添加一件事一个>:
也不要忘記 META 標籤(像這樣,或 它的 HTML4 或 XHTML 版本):
<meta charset="utf-8">
這看起來微不足道,但 IE7 之前曾經給我帶來過問題。
我所做的一切都是正確的;資料庫、資料庫連接和Content-Type HTTP標頭都設定為UTF-8,在所有其他瀏覽器中都運作良好,但Internet Explorer仍然堅持使用「西歐」編碼。
原來該頁面缺少 META 標記。添加即可解決問題。
編輯:
W3C 其實有一個相當大的專門討論 I18N 的部分。他們有許多與此問題相關的文章 - 描述了 HTTP、(X)HTML 和 CSS 方面的內容:
他們建議同時使用 HTTP 標頭和 HTML 元標記(或在 XHTML 充當 XML 的情況下使用 XML 宣告)。
P粉7636623902023-08-28 09:05:50
資料儲存:
Specify the utf8mb4
character set on all tables and text columns in your database. This makes MySQL physically store and retrieve values encoded natively in UTF-8. Note thatv. #utf8mb4 encoding if a
utf8mb4_* collation is specified (without any explicit character set).
utf8, which only supports a subset of Unicode characters. Iding wish I were kidding .
資料存取:
utf8mb4. This way, MySQL does no conversion from its no conversion from its native UTF-8 when it hands data off to your application and vice versa.
PDO abstraction layer with PHP ≥ 5.3.6, you can specify charset in the
DSN:
$dbh = new PDO('mysql:charset=utf8mb4');
mysqli, you can call set_charset():
$mysqli->set_charset('utf8mb4'); // object oriented style mysqli_set_charset($link, 'utf8mb4'); // procedural style
mysql but happen to be running PHP ≥ 5.2.3, you can call #mysql_set_charset.
utf8 applies as above.
UTF-8 should be set in the HTTP header, such as
Content-Type: text/html; charset=utf-8default_charset
in php.ini (preferred), or manually using header()
function.
如果您的應用程式將文字傳輸到其他系統,它們還需要了解字元編碼。對於 Web 應用程序,必須告知瀏覽器發送資料的編碼(透過 HTTP 回應標頭或
HTML 元資料 as a second parameter.
does the trick, but you have to use it religiously. There's really no way around this, as malicious clients can submit data in whatever encoding they want, and I haven' get PHP to do this for you reliably.
:
mbstring extension.
not by default UTF-8 safe. There are some things you can safely do with normal PHP string operations (like concatenation) , but for most things you should use the equivalent mbstring function.
中的任何鏈接,獲取一些很好的資源,以了解您需要了解的所有內容。 p>