UTF-8 BOM and PHP
We had a site that must be internationalized, to be available in several European languages, so we used UTF-8 string encoding throughout. This, however, was not without a certain number of headaches having all types of display issues in the browsers; mainly extra line spaces showing up that were not obvious from the html source, and of course IE (7, 8 &9) going into quirks mode. The problem turns out to be that we had BOMs. http://en.wikipedia.org/wiki/Byte_order_mark
So to provide some possible help to other that go down this route here is what we found.
2. None of the browsers we tested; FireFox, Chrome, and IE support the BOM.
3. If you use MS windows notepad to save a UTF-8 file it will automatically add a BOM. So NEVER ever use notepad. Of course the browser with the biggest problems with the BOM is IE.
4. We use Netbeans as an IDE. If a file contains a BOM and you edit and save it with Netbeans it will still contain the BOM. If you copy/paste a file in Netbeans that has a BOM the result will also have a BOM. If you start a new UTF-8 file in Netbeans it will not have a BOM.
5. So how did we identify this problem? The browser will identify the encoding from the meta tag if it is present. <meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8"/>,. We loaded the page (in FireFox) then told it to change the encoding to ISO-8859-1. The BOM will show up before the <!DOCTYPE HTML> at the beginning of the file as 3 strange marks.
6. So how did we how find out which of our files had BOMs. We used the following code. We didn’t write this, we found it on another site but we did not make a note of the author. So if the original author sees this post please feel free to add your credit or add a post and I will do it for you.
Having removed all the BOMs everything on the site compiles and runs without problem.
Hope we can save you the time it took us to identify and solve this problem.
Just wrapped your code in php vbb tags :)
Besides this, good work!
|All times are GMT +2. The time now is 21:08.|
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.