Get Social

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.


7 CommentsLeave a Comment

  • Reply


    6 months ago

    ¡¡ Great !! Thank you so much for that.

  • Reply


    6 months ago


  • Reply


    5 months ago

    Works great, I had a file with a BOM problem and I didn’t manage to remove it with Aptana or Edit++.
    I just used this script on my server and now everything works great.

  • Reply


    4 months ago

    very very thankyou…

  • Reply


    3 months ago

    Works Great.. Thank You So Much !!!

  • Reply

    Paulo Oliveira

    2 months ago

    Thank you!

  • Reply


    13 weeks ago

    you saved my life!
    i had a lot of work done, when i realized all my files are badly encoded and i had no backup.


Leave a Reply