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

瘦欲@ 提交于 2019-12-23 03:17:14

问题


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).


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/15222182/how-do-i-add-a-bom-to-all-utf-8-files-in-a-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!