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.

 

6 CommentsLeave a Comment


  • Reply

    pinpinelea

    6 months ago

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

  • Reply

    André

    5 months ago

    Thanks!

  • Reply

    Matan

    4 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.
    Thanks!

  • Reply

    harbinder

    4 months ago

    very very thankyou…

  • Reply

    Nishita

    2 months ago

    Works Great.. Thank You So Much !!!

  • Reply

    Paulo Oliveira

    1 month ago

    Thank you!

Leave a Reply