3
I have several file problems in UTF-8 with BOM, several tokens are being generated at the beginning of the pages, this causes several problems in the reading of json files and desindentation of HTML components. Almost impossible to find out because the tokens are invisible. I googled a way to change all files to UTF-8 without BOM and found a perl script to remove the BOM signature but it didn’t work. Someone could help. I need a script that changes all project files.
More information about the problem and the script can be found here
My solution for now is to go digging the files and saving in UTF-8 without BOM, but they are several files, so I thought of a script, but I have no idea how to do.
The momentary solution to json token problems I did so to resolve (POG):
1.I retrieve the string from the first key { found. Because tokens are generated before this key. This solves momentarily. But it is a gambit.
json = json.substring(json.indexOf("{"),json.length);
objeto = $.parseJSON(json);
Does it have to be in Perl? And do you really need a full script, or are you already working on some language and can you just embed a small chunk of code? Removing BOM is trivial, just read the first three bytes of the file and - if they match a certain pattern - create a new file from the 4th byte forward. Assuming UTF-8, of course.
– mgibsonbr
It doesn’t have to be in Perl, I’ve never actually programmed in Perl. So any language can be done. I use linux sometimes even have a program that does this but I do not know. Thanks @mgibsonbr, it seems simple to do for one after Voce explained, the problem I think will be identify the file format and do a search in all project directories.
– Skywalker
I can try to do if there is no script already ready.
– Skywalker
Are you using Javascript? Would you solve a code to eliminate BOM in Javascript, just before you use it? (or you really need to convert the files locally?)
– mgibsonbr
i want to remove the BOM in all project files. Javascript was an example of how I managed to get around the problem in a certain circumstance. But what I wanted was a code similar to the one made in perl of the site I mentioned. But I couldn’t make it work here.
– Skywalker
soon I will try to follow your hint and I will try to do the script in python or in c.
– Skywalker
I’m writing an answer, I thought it might be something simpler.
– mgibsonbr
can answer. Your answer may be useful.
– Skywalker