tags:

views:

107

answers:

1
header('content-type: application/xml');
echo '<'.'?xml version="1.0"?'.'>';
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;';
echo '<root>';
$hierarchy=$tree->getArray();
recursiveBuild($hierarchy[0]);
echo '</root>';

I am printing this as output to get XML... can i get these contents in a File.xml instead of file.php

Instead of seeing the xml in a php file, i need this to be outputted in direct XML.

+2  A: 

You could buffer the output with the Output Buffering Control and write the buffered data into a file with file_put_contents:

ob_start();
echo '<'.'?xml version="1.0"?'.'>';
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;';
echo '<root>';
$hierarchy=$tree->getArray();
recursiveBuild($hierarchy[0]);
echo '</root>';
file_put_contents('file.xml', ob_get_contents());
ob_end_clean();
Gumbo
How can i place the file in particular directory....
Just change `file.xml` to the path you want.
Gumbo