Fix validation 'Byte-Order Mark found in UTF-8 File' in drupal installations

So I stumbled across this issue the other day. I usually make sure I save all my files as Encoded as UTF-8 without BOM. But somehow, somewhere there may be a file that was saved incorrectly and thus it will give you a validation error on w3c.

Now, how do you go about finding which file is causing the error? Is it a theme file, or is it a custom module or is it a drupal file which you may have modified (I know, hacking drupal core is BAD!)

The solution is: run a shell script to find the file causing the issue.

Find the BOM files:

grep -rl $'\xEF\xBB\xBF' .

Find and fix the BOM files:

find . -type f -exec sed '1s/^\xEF\xBB\xBF//' -i.bak {} \; -exec rm {}.bak \;

I have to thank Denis on More info can be found here:

And in case you were wondering, my error resided in a javascript file for a custom module. The above shell script saved me a lot of time - else I would have had to open all files and resave them without BOM if they weren;'t already.

On another note: image files will not give you the error message on w3c ;-)