Taking the BOM out of Joomla
I recently had an issue that hit a couple of the Joomla websites, as well as my own. It turns out I was part to blame but the problem I found was reasonably common elsewhere. Suddenly I was experiencing the UTF-8 BOM (Byte-Order Mark) and it was causing all sorts of problems including wrecking my XMAP sitemap, screwing the styling when viewing the site through Internet Explorer and various glitches that went largely un-noticed until I eventually fixed the problem and the glitches disappeared too.
The fix, once I worked it out, took minutes but the problem bugged me for days. Find out what tools I used to identify the problem then solve it quickly.
My own website and a number of others I manage using Joomla had been running fine for a while. I registered them all with Live.com and Yahoo search engines and during this time thought it would be a good idea to write a pair of plugins to make it easier for me now and in the future. I have also published these plugins on the Joomla Extensions Directory. I am a windows user and it turns out that while using Visual Studio 2008 to edit my code I had unknowingly saved the .php files in a UTF-8 encoding which had also added the BOM at the beginning of the file. That was where the problem began.The Symptoms
I first noticed a problem through Google webmaster tools when my otherwise perfect XMAP generated XML sitemap was reporting errors. This was strange because I hadn't any problems before. I used the validations tools at http://www.validome.org/ and they all seemed to check out ok. My main browser is Google Chrome, most days I use Firefox 3 and when I have to test websites I use Internet Explorer. I noticed that the page layout and font sizing was slightly off in IE. It was then I brought out my old, friend the Yellowpipe Lynx Viewer Tool which I use as a Firefox Add-on, and I found the tell-tale "" at the start of my sitemap and on most pages of my website. Somewhere in there was a BOM so all I had to do was find it!
Finding the BOM
Finding the BOM in all the various modules, plugins and components of Joomla is like finding the proverbial needle in a haystack. I tried enabling / disabling the recently added extensions one by one but this didn't help. In order to find this then it called for something a but more grown up.
I have been using GREP32.exe on my Windows platform for years and most of the time it does the job. It doesn't support folder recursion however and the Joomla tree it pretty big. I went hunting and found Cygwin which gives a Linux-ish shell in Windows. In there is a proper port of the grep tool and with a little help from an article I found on the Joomla forums I ran the following to find all files with the BOM at the start of the file.
grep -rl $'\xEF\xBB\xBF' /home/<myUsername>/<myJoomlaFolder>This brought back about 30-odd files, some images and some text. There were a few of the JoomlaPack language.ini files, Linkr and RandomImage language files and - sadly - two of my own plugins.
Diffusing the BOM
The fix was easy. I happen to use Streamline.net for hosting and just edited the files using their online FTP tool and resaved as ANSI. If I were fixing this on my own PC the simplest way to have rectified the issue would be top open each offending file in Notepad.exe and gone to File... Save As... and overwritten the original, remembering to choose ANSI encoding instead of UTF-8.
Last Updated (Tuesday, 07 October 2008 15:59)

