PHP 4 and 5 and UTF-8 BOM issues

handgestrickts favourite source-code-editor is Ultraedit 32. this editor, like many other modern editors, has a good feature to mark files as UTF-8 encoded. this mark is called BOM (byte order mark) and is a 2-4 bytes mark in the beginning of a file, that indicates which Unicode-type is used. what a brilliant idea.

unfortunately PHP 4 and 5 send these marks as output to the browser. so if later you use a session_start()- or header()-function somewhere, you end up with the error message "headers already sent in ...".

after searching the web, we found the solution: PHP 5.2.0 introduces the configure-switch --enable-zend-multibyte. this switch enables PHP to recognize the BOM as what it is. unfortunately you have to recompile PHP.

for people using PHP on windows or others hosting on a shared public webserver, there are other workarounds: the first line in your PHP code should be a comment with a Unicode-character inside, like german "Umlaute", for example. then you save this file as UTF-8 without BOM. the editor should now recognize the special character as UTF-8 encoded and switch to the right encoding.

good news for the future: PHP 6 will have a widespread Unicode-support also enabling this feature by default.

Thursday, 26. July 2007 • trackback url

Re: PHP 4 and 5 and UTF-8 BOM issues

Ok. thanks for the info. We'll try it out. We're having the issue of utf8 not being displayed on php4 correctly.

Reply

Tuesday, 27. May 2008 • dreamluverz • • wwwReply

trackback url

Re: PHP 4 and 5 and UTF-8 BOM issues

Very Important workaround for Window users/hosting on a shared public webserver.

Reply

Wednesday, 05. November 2008 • Satya Prakash Karan • • wwwReply

trackback url

Add Comment

( to reply to a comment, click the reply link next to the comment )

Comment Title:
Your Name:
Email Address:
Make Public?
Website:
Make Public?

Comment:


Allowed XHTML tags : a, b, i, strong, code, acrynom, blockquote, abbr. Linebreaks will be converted automatically.


Captcha:

captcha image

please type the content of the above image into the following form-field: