如何向项目中的所有UTF-8文件添加BOM? [英] How do I add a BOM to all UTF-8 files in a project?

查看:818
本文介绍了如何向项目中的所有UTF-8文件添加BOM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前的编码是UTF-8,我想为所有文件添加BOM。

Current encoding is UTF-8 and I want to add BOM to all the files

上下文:Windows 8应用程序认证工具包抛出以下错误,如果未添加BOM :

Context: Windows 8 app certification toolkit throws following error, if BOM is not added:

文件C:\x\y\z.js不正确编码UTF-8。将文件重新保存为UTF-8(包括字节顺序标记)。

File C:\x\y\z.js is not properly UTF-8 encoded. Re-save the file as UTF-8 (including Byte Order Mark).

推荐答案

我知道这是一个旧问题,但是在这里是如何做到的:

I know this is an old question but here is how I did it:

创建一个php文件:addBOMtoFile.php并添加以下行:

create a php file: addBOMtoFile.php and add the following line:

file_put_contents("some_new_file_name.js", "\xEF\xBB\xBF" . mb_convert_encoding(file_get_contents("some_file_name.js"), "UTF-8", "UTF-8"));

C:\php> php addBOMtoFile.php

C:\php>php addBOMtoFile.php

这篇关于如何向项目中的所有UTF-8文件添加BOM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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