PHP Output buffering contains something before scr

2019-09-07 03:04发布

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

4条回答
等我变得足够好
2楼-- · 2019-09-07 03:10

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.

查看更多
男人必须洒脱
3楼-- · 2019-09-07 03:14

perhaps a case of BOM character? more info here

查看更多
我命由我不由天
4楼-- · 2019-09-07 03:21

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 ;)

查看更多
【Aperson】
5楼-- · 2019-09-07 03:25

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.

查看更多
登录 后发表回答