homepage Welcome to WebmasterWorld Guest from 54.237.54.83
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
frustrating php output buffer problem.
adephue




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

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();
ob_end_clean();
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";
break;
case 2:
if (is_array($t)) for ($i=0,$j=count($t);$i<$j;$i++) $carpoutput.=$t[$i];
else $carpoutput.=$t;
break;
default:
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.

 

phparion




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

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.

adephue




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

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

default:
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();

coopster




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved