[thelist] Trapping output of php script?

Aredridel aredridel at nbtsc.org
Wed Jul 23 11:56:19 CDT 2003


On Wed, 2003-07-23 at 02:59, Joel Konkle-Parker wrote:
> I'm attempting to incorporate a YaBB forum into my current site layout. To
> accomplish this, I want to be able to run a wrapper script that in turn runs
> YaBB's index.php and traps the output into a variable.
> 
> Something similar to $output = require ("YaBBindex.php"), if that worked as it
> looks like it could.
> 
> Any suggestions?

Just one -- the only one.  Use ob_start() and ob_end(), thus:

ob_start();
require('YaBBindex.php');
$output = ob_get_contents();
ob_end_clean();

I use this extensively in my code -- I generate simple, clean XHTML
output in all my scripts -- then the output buffer functions get called,
which apply XSL stylesheets to make them into more stylish code, and, if
XHTML is not supported on the browser I'm targetting, it recodes it to
HTML 4.0, and can drop CSS and all sorts of things.

It makes for very clean code.

Ari




More information about the thelist mailing list