問題描述
您會推薦哪些擴展以及如何最好地配置 php 以創建一個對所有內容都使用 utf-8 編碼的網站.例如...
What extensions would you recommend and how should php be best configured to create a website that uses utf-8 encoding for everything. eg...
- 頁面輸出為 utf-8
- 表單提交以 utf-8 編碼的數據
- 字符串數據的內部處理(例如與數據庫對話時)也都是 utf-8 格式.
目前看來 php 并不能很好地處理多字節字符集.到目前為止,我已經發現 mbstring 看起來像是一個重要的擴展.
It seems that php does not really cope well with multibyte character sets at the moment. So far I have worked out that mbstring looks like an important extension.
值得麻煩嗎..?
推薦答案
PHP 與 Unicode 內容的假設問題有些夸大其詞.自 1998 年以來,我一直在做多語言網站,直到我在某處讀到它時才知道可能會出現問題 - 多年后和網站.
The supposed issues of PHP with Unicode content have been somewhat overstated. I've been doing multilingual websites since 1998 and never knew there might be an issue until I've read about it somewhere - many years and websites later.
這對我來說很好用:
Apache 配置(在 httpd.conf 或 .htaccess 中)
Apache configuration (in httpd.conf or .htaccess)
AddDefaultCharset utf-8
PHP(在 php.ini 中)
PHP (in php.ini)
default_charset = "utf-8"
mbstring.internal_encoding=utf-8
mbstring.http_output=UTF-8
mbstring.encoding_translation=On
mbstring.func_overload=6
MySQL
CREATE
使用 utf8_*
整理的數據庫,讓表繼承數據庫排序規則和使用 "SET NAMES utf8"
CREATE
your database with an utf8_*
collation,
let the tables inherit the database collation and
start every connection with "SET NAMES utf8"
HTML(在 HEAD 元素中)
HTML (in HEAD element)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
這篇關于如何最好地配置 PHP 以處理 UTF-8 網站的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!