Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

frustrating php output buffer problem.



2:00 am on Oct 11, 2007 (gmt 0)

5+ Year Member

I am using php's output buffer to grab the output of a script (file called by include() and place that output into a variable that will later be parsed into a template.

The process works with all of my scripts except for one that displays an rss feed. No matter what, the output makes it to the browser even w/ output buffering on. Here's my function...

function parseScript ($script) {
ob_start ();
include_once $_SERVER['DOCUMENT_ROOT'].$script;
$temp = ob_get_contents();
return $temp;

Here is the output function of the script whose output I am trying to capture with the output buffer...

function CarpOutput($t) {
global $carpconf,$carpoutput;
if (is_array($t)) { for ($i=0,$j=count($t);$i<$j;$i++) $t[$i]=ereg_replace("&apos;","'",$t[$i]); }
else $t=ereg_replace("&apos;","'",$t);
switch ($carpconf['outputformat']) {
case 1:
if (!is_array($t)) $t=explode("\n",$t);
for ($i=0,$j=count($t);$i<$j;$i++) echo 'document.writeln("'.str_replace('"','\"',trim(str_replace("\r",' ',$t[$i])))."\");\n";
case 2:
if (is_array($t)) for ($i=0,$j=count($t);$i<$j;$i++) $carpoutput.=$t[$i];
else $carpoutput.=$t;
if (is_array($t)) for ($i=0,$j=count($t);$i<$j;$i++) echo $t[$i];
else echo $t;

Any ideas would be greatly appreciated.


5:00 am on Oct 11, 2007 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

which section runs for xml in switch? what EXACT error/problem you are facing.. explain in a little details?

Also you should try header("content-type: html/xml"); if you want to grab xml output and display it somewhere.


9:36 am on Oct 11, 2007 (gmt 0)

5+ Year Member

OK, the switch statement is evaluating $carpconf['outputformat'] which is set to 0 by script in its config array so the default: statement is picking it up...

if (is_array($t)) for ($i=0,$j=count($t);$i<$j;$i++) echo $t[$i];
else echo $t;

The bold part is what is echoing out the data and it is just html when I do a var_dump();


1:45 pm on Oct 15, 2007 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Welcome to WebmasterWorld, adephue.

Are you certain that your output buffering is still on at this point? You can check the stack level [php.net] to be certain.


Featured Threads

Hot Threads This Week

Hot Threads This Month