标题内容类型带有BOM的字符集UTF-8 [英] Header Content Type Charset UTF-8 with BOM

查看:135
本文介绍了标题内容类型带有BOM的字符集UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在制作一些文件,有些文件需要下载和上传。该文件具有不同的编码,并且仅当文件以包含BOM的UTF-8打开时才有效。



目前,我正在使用这个简单的头文件头文件('Content-Type:text / html; charset = utf-8'); 但我怎样才能改变设置,因此文件文件将被视为带有BOM的UTF-8。 b
$ b

希望得到一些帮助。
Thanks!

解决方案

绝对不需要在HTML文件中包含BOM。 (如果它真的包含不同的编码,那么UTF-8 BOM会被打破,所以听起来你有点困惑。)



如果你期望文件将其保存到磁盘并用于不需要UTF-8的地方,您可以添加一个元素来指示编码:

< meta http-equiv ='Content-Type'content ='text / html;如果实际上你使用的是不同于UTF-8的编码,那么,而不是BOM,只需更改meta属性中的值即可。



如果您真的必须拥有BOM,那么您需要确保它是您输出的第一件东西,例如



echo\xEF\xBB\xBF;



请参阅为一个实际上有意义的例子。


Im currently making a file that some have to download and upload. The file have som differents encodings and it only works if the file is opened with UTF-8 with BOM.

Currently im using this simple header header('Content-Type: text/html; charset=utf-8'); but how can i change the settings so file file would be seen as UTF-8 with BOM.

Hoping for some help. Thanks!

解决方案

There's absolutely no need to include a BOM in an HTML file. (If it really includes different encodings, then a UTF-8 BOM would be broken, so it sounds like you're a bit confused.)

If you expect the file to be saved to disk and used in places where UTF-8 isn't expected, you could add a meta element to indicate the encoding as well:

<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>

If in fact you are using a different encoding than UTF-8, then rather than a BOM, just change the value in the meta attribute.

If you really must have a BOM in there then you'll need to make sure that it's first thing you output, e.g.

echo "\xEF\xBB\xBF";

See How can I output a UTF-8 CSV in PHP that Excel will read properly? for an example where that actually makes sense.

这篇关于标题内容类型带有BOM的字符集UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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