PHP Output buffering contains something before script starts

一曲冷凌霜 提交于 2019-12-24 23:30:26

问题


i have a site, where i buffer some output with

ob_start();
... 

and it worked fine until today i updated my debian from an older php5.3 to the latest php5.3.3-7+squeeze8
Now i sometimes have something in the output buffer before i call it the first time

please don't answer things like

"header must be called before any output is sent." (I know, I work a lot with output buffers)

when i set an extra ob_get_clean(); at the very first line of my script, it works

<?
ob_get_clean();

it seems, like php is creating some output beforehand if i put the first line

<? print_r(ob_get_clean()); ?>

then i see, that there is an empty string already in the buffer:

""

on all other pages it isn't, there ob_get_clean(); contains

null


回答1:


is it possible you have some " " in front of your <?php somewhere? or wrong file encoding issue its usually some kind of that nature, check your files and include files.




回答2:


Now i sometimes have something in the output buffer before i call it the first time

It'll be much easier if you give us some info about that mysterious data.




回答3:


perhaps a case of BOM character? more info here




回答4:


i found it:

i had no invisible character in front, it was something different: i called ob_end_clean() one time too much:

this was my code, inside a function i call:

function print_something(){
ob_start();

echo some stuff...

echo ob_get_clean();
ob_end_clean(); // this was the bug! 
}

it seems, that you can clear your main output buffer ;)



来源:https://stackoverflow.com/questions/10072569/php-output-buffering-contains-something-before-script-starts

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