PHP:如何创建编码为“没有BOM的UTF-8"的文件; [英] PHP: How to create a file encoded as "UTF-8 without BOM"

查看:441
本文介绍了PHP:如何创建编码为“没有BOM的UTF-8"的文件;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,你们中的大多数人都知道我们对文件使用以下编码:

As I guess, most of you know that we have the following encodings for files:

  • ANSI
  • UTF-8

通过在文件的开头添加三个字符可以识别UTF-8,但是您知道这些字符在PHP语言中造成了一些麻烦 因此,我们使用

UTF-8 is recognized by adding three chars at the beginning of the file but those chars causes some troubles in PHP Language as you know So we use

  • 不带BOM的UTF-8(而不是UTF-8)

这是我的问题: 我们如何使用frwite()或任何其他函数(无关紧要)编写编码为(UTF-8不带BOM的)新文件(使用PHP)

Here is my question: How can we write a new file (Using PHP) with the encoding of (UTF-8 Without BOM) either using frwite() or any other function (Doesn't matter)

(我不是在询问编辑器设置>我是在询问使用php函数创建文件)

(I'm not asking about an editor settings> I'm asking about creating a file with php functions)

推荐答案

恐怕您在问题中误用了UTF-8和ANSI.

I'm afraid you have misrepresented both UTF-8 and ANSI in your question.

UTF-8不需要 在其开始时具有BOM.没有像没有BOM的UTF-8"这样的编码.只有"UTF-8".我已经处理了数百万个(当然,成千上万个)UTF-8文件,而且从未在开始时遇到过BOM.

UTF-8 is not required to have a BOM at its start. There's no such encoding as "UTF-8 without BOM" encoding. There's just "UTF-8". I've processed millions (well, certainly hundreds of thousands) of UTF-8 files and never once come across a BOM at their start.

根据 Unicode标准,物料清单是既不是必需的也不是推荐的:

2.6编码方案

对于UTF-8,既不需要也不建议使用BOM,但是在从其他使用BOM的编码形式转换UTF-8数据或BOM用作UTF-8签名的情况下,可能会遇到BOM的情况. .有关更多信息,请参见特殊的16.8节中的字节顺序标记"小节.

2.6 Encoding Schemes

Use of a BOM is neither required nor recommended for UTF-8, but may be encounter in contexts where UTF-8 data is converted from other encoding forms that use a BOM or where the BOM is used as a UTF-8 signature. See the "Byte Order Mark" subsection in Section 16.8, Specials, for more information.

此外,没有"ANSI"这样的编码!

IANA提供的最接近的东西提供给字符集的"ANSI"名称是"ANSI_X3.4-1968"和"ANSI_X3.4-1986",它们都是"US-ASCII"(首选的MIME名称)的旧别名,"US-ASCII"(128个代码点的7位编码).没有其他官方字符集名称的名称中包含"ANSI".

The closest thing that IANA provides provides to "ANSI" for a character set name is "ANSI_X3.4-1968" and "ANSI_X3.4-1986", which are both just legacy aliases for "US-ASCII" (the preferred MIME name), a 7-bit encoding of 128 code points. There is no other official charset name contains "ANSI" in its name.

我不确定您在什么环境下运行,但这似乎使您陷入了一些非标准的命名,期望和标准.

I'm not sure what environment you're operating under, but it seems to have led you into some very non-standard naming, expectations, and standards.

可能是Windows™吗? ☹

Could it perhaps be… Windows™? ☹

刚刚找到关于这个假名来源的此答案.

Just found this answer about the source of this misonymy.

这篇关于PHP:如何创建编码为“没有BOM的UTF-8"的文件;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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