0

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?
Community
  • 1
  • 1
Levent Esen
  • 559
  • 7
  • 18
  • 1
    There are hundreds of SO questions related to php and BOMs - do none of them provide you an answer? – AD7six Dec 04 '12 at 12:08
  • @AD7six , I couldn't find anyone asks if is it a bug – Levent Esen Dec 04 '12 at 12:26
  • If adding the BOM makes your scripts not work, then the solution is the same as in that old doctor joke. "Doctor, it hurts when I do this". "Well don't do that, then!" – GordonM Nov 04 '13 at 11:57

2 Answers2

0

BOM is actual data sent to the browser and however the browser will ignore it, once it is sent you are unable to send headers unless you use output buffering. In general do not use BOM. If your text editor you work with requires BOM, then change the editor to something less outdated.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
0
  • 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.
RickN
  • 12,537
  • 4
  • 24
  • 28
  • I am not sure if PHP is working as intended because BOM is for control not content – Levent Esen Dec 04 '12 at 12:28
  • Just because it's not a printable character doesn't mean it shouldn't be outputted. And as the documentation says, *any* output before your headers results in the 'headers already sent' error. If I were to create an otherwise empty page containing only a right-to-left control character, I'd expect it to be printed. – RickN Dec 04 '12 at 12:45
  • Well it is, anything outside – Esailija Dec 04 '12 at 12:45