問題描述
在PHP Cookbook"中,他們說 (p.589) 要將輸出數據的字符編碼正確設置為 utf-8,必須將 default_encoding
配置編輯為 utf-8.
In the "PHP Cookbook", they say (p.589) that to properly set the char encoding of outgoing data to utf-8 it is necessary to edit the default_encoding
configuration to utf-8.
然而,我在php.ini
中找不到這個配置.我應該簡單地添加一行表示 default_encoding = "utf-8"
嗎?
However, I cannot find this configuration in php.ini
. Should I simply add a line that would say default_encoding = "utf-8"
?
我確實有一個 ;default_charset = "iso-8859-1"
.正如你所看到的 (;
),現在它沒有被激活.我應該刪除分號并將其設置為 "utf-8"
嗎?這會處理默認編碼嗎?
I do have a ;default_charset = "iso-8859-1"
. As you can see (;
), right now it is not activated. Should I remove the semi-colon and set it to "utf-8"
? Does that take care of the default encoding?
我還發現了其他我不知道該怎么做的編碼指令:
I also found other encoding directives that I don't know what to do about:
[iconv]
;iconv.input_encoding = ISO-8859-1
;iconv.internal_encoding = ISO-8859-1
;iconv.output_encoding = ISO-8859-1
...
; http://php.net/exif.encode-unicode
;exif.encode_unicode = ISO-8859-15
...
;mssql.charset = "ISO-8859-1"
...
;exif.encode_unicode = ISO-8859-15
有什么理由我不應該簡單地將它們全部替換為 utf-8
?
Is there any reason why I shouldn't simply replace them all with utf-8
?
推薦答案
您應該將 default_charset
設置為 UTF-8:
You should set your default_charset
to UTF-8:
default_charset = "utf-8"
(如果 PHP Cookbook 要求您更改 default_encoding
,則其中可能有錯字 — 我從未聽說過.)
(PHP Cookbook may have a typo in it if they ask you to change the default_encoding
— I've never heard of it.)
如果您要輸出 UTF-8 編碼的字符,您還需要確保您的網絡服務器設置為輸出 UTF-8.在 Apache 中,這可以在 httpd.conf 文件中設置:
You'll also want to make sure that your webserver is set to output UTF-8 if you're going to outputting UTF-8 encoded characters. In Apache this can be set by in the httpd.conf file:
AddDefaultCharset UTF-8
至于修改iconv
、exif
和mssql
編碼設置,你可能不需要設置這些(你的設置有這些無論如何都被注釋掉了)但無論如何將它們全部更改為 UTF-8 是個好主意.
As for modifying the iconv
, exif
, and mssql
encoding settings, you probably don't need to set these (your settings have these commented out anyhow) but it's a good idea to change them all to UTF-8 anyhow.
這篇關于將 PHP 默認編碼設置為 utf-8?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!