将PHP默认编码设置为utf-8? [英] Setting PHP default encoding to utf-8?

查看:715
本文介绍了将PHP默认编码设置为utf-8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,

在PHP Cookbook中,他们说(p.589)正确设置输出数据的char编码为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.

但是,我在<$ c中找不到此配置$ c> 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" ?

code>; 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编码字符,请确保您的Web服务器设置为输出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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆