Get Social

All posts tagged byte order mark

Take 2 on UTF8 BOM : Remove BOM with PHP

Some people asked me about my UTF8 BOM problems in PHP and XML. They were wondering if it was possible to remove the BOM from the files, without damaging them. And if PHP could do this. They had hundreds of files with UTF8 BOM in them and it would be time consuming to remove by hand, if they weren’t able to find a solution.

My answer was, “of course”. PHP can read and remove BOM from every file. As we encounter this problem only in text based files, a string remover will do the trick. Applause for substr().

I wrote a php based bom remover that works both from web and command line. You can download/fork the code from the github repository.

Please backup your files before running the script.