« 慎用Tor | Main | 哭笑不得 »

php错误"Cannot modify header information - headers already sent by"

php错误"Cannot modify header information - headers already sent by"

这都是因为utf-8编码文件含有的bom原因,而php4,5都是不支持bom的。去掉bom,可以用ultraedit打开一个新文件然后另存为时选择“utf-8 无BOM”即可。
------------

UTF-8 编码的文件可以分为no BOM 和 BOM两种格式。
何谓BOM? "EF BB BF" 这三个字节就叫BOM,BOM的全称叫做"Byte Order Mard".在utf-8文件中常用BOM来表明这个文件是UTF-8文件,而BOM的本意实在utf16中用来表示高低字节序列的。
在字节流之前有BOM表示采用低字节序列(低字节在前面),而utf8不用考虑字节序列,所以其实有无BOM都可以。

微软的记事本 Word 等只能正确打开含BOM的UTF8文件,然后UltraEdit却恰恰相反,回把BOMutf8文件 误认为ascii编码。

UTF-8的BOM是 EFBBBF,因为UE载入UTF-8文件会转成Utf16,上述的EFBBBF 在Utf16中是FFFE(Unicode-LE的BOM),UltraEdit不认识BOM又加多一個BOM,所以有2个FFFE。
文件就被它破坏了。


Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on September 9, 2007 10:33 PM.

The previous post in this blog was 慎用Tor.

The next post in this blog is 哭笑不得.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.