在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模板网!