問(wèn)題描述
在PHP Cookbook"中,他們說(shuō) (p.589) 要將輸出數(shù)據(jù)的字符編碼正確設(shè)置為 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
中找不到這個(gè)配置.我應(yīng)該簡(jiǎn)單地添加一行表示 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"
?
我確實(shí)有一個(gè) ;default_charset = "iso-8859-1"
.正如你所看到的 (;
),現(xiàn)在它沒(méi)有被激活.我應(yīng)該刪除分號(hào)并將其設(shè)置為 "utf-8"
嗎?這會(huì)處理默認(rèn)編碼嗎?
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?
我還發(fā)現(xiàn)了其他我不知道該怎么做的編碼指令:
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
有什么理由我不應(yīng)該簡(jiǎn)單地將它們?nèi)刻鎿Q為 utf-8
?
Is there any reason why I shouldn't simply replace them all with utf-8
?
推薦答案
您應(yīng)該將 default_charset
設(shè)置為 UTF-8:
You should set your default_charset
to UTF-8:
default_charset = "utf-8"
(如果 PHP Cookbook 要求您更改 default_encoding
,則其中可能有錯(cuò)字 — 我從未聽(tīng)說(shuō)過(guò).)
(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 編碼的字符,您還需要確保您的網(wǎng)絡(luò)服務(wù)器設(shè)置為輸出 UTF-8.在 Apache 中,這可以在 httpd.conf 文件中設(shè)置:
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
編碼設(shè)置,你可能不需要設(shè)置這些(你的設(shè)置有這些無(wú)論如何都被注釋掉了)但無(wú)論如何將它們?nèi)扛臑?UTF-8 是個(gè)好主意.
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.
這篇關(guān)于將 PHP 默認(rèn)編碼設(shè)置為 utf-8?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!