Were you ever hit by the PHP warning:
Warning: Cannot modify header information - headers already sent by (output started at some/file.php:1) in some/other/file.php on line 123 ?
The first line of the file in question some/file.php looks innocent:
<?php
A standard PHP code opening tag. So, where are the outputted characters?
Well… Welcome to Unicode world. With multibyte characters there is a need of distinguishing low-endian from high-endian encoded files. It’s a job of the BOM – byte-order mark – it is an invisible, no length space with a unique two bytes character code U+FEFF. It does not affect the rendered content of the document and it is easy to detect the endianness of the document.
But PHP is not a renderer – it takes the two bytes literally and sends them to browser. But before any content, it needs to send HTTP headers. The rest of the story is obvious – you cannot modify already sent headers and PHP warns you about the fact.
How to remove BOM?
It’s not that easy – in most editors it is not an editable character and they just leave it as-is. For me, the easiest way is to open the file in SciTE, change the File -> Encoding from UTF-8 with BOM to UTF-8 and save it.


0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.
You must be logged in to post a comment.