How do I capture PHP output into a variable?

<?php ob_start(); ?>
<xml/>
<?php $xml = ob_get_clean(); ?>
<input value="<?php echo $xml ?>" />͏͏͏͏͏͏

Put this at your start:

ob_start();

And to get the buffer back:

$value = ob_get_contents();
ob_end_clean();

See http://us2.php.net/manual/en/ref.outcontrol.php and the individual functions for more information.


It sounds like you want PHP Output Buffering

ob_start(); 
// make your XML file

$out1 = ob_get_contents();
//$out1 now contains your XML

Note that output buffering stops the output from being sent, until you "flush" it. See the Documentation for more info.