utf-8 bom and headers in php [duplicate]

ε祈祈猫儿з 提交于 2019-12-12 05:56:05

问题


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?

回答1:


  • 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.



回答2:


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.



来源:https://stackoverflow.com/questions/13702522/utf-8-bom-and-headers-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!