How do I add a BOM to all UTF-8 files in a project

2019-05-30 14:55发布

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

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

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

2条回答
手持菜刀,她持情操
2楼-- · 2019-05-30 15:17

If you are using IDE like eclipse or netbeans, you can select all files and set the encoding. Other option is open all files in text editor and change.

查看更多
我命由我不由天
3楼-- · 2019-05-30 15:29

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

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

查看更多
登录 后发表回答