Search code examples
phputf-8http-headersbyte-order-mark

utf-8 bom and headers in php


Possible Duplicate:
“Warning: Headers already sent” in PHP

When I create my php files with utf-8 bom, the header() function doesn't work because the bom chars are sent before the http headers.

  • Does it mean that we shouldn't use bom in php source files?
  • Is it a feature or bug?
  • And what are your advices when working with utf-8 encoded php source files?

Solution

    • The BOM is useless in UTF-8.
    • It's neither. PHP is working as intended. Your file consists of this, and PHP is working as intended, because it outputs all data before the opening <?php tag first:

    --

    <byte order mark><?php // code here
    

    --

    • Don't use BOM.