Kevin
Kevin

Reputation: 23634

Output in XML using PHP

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">';
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.

Upvotes: 0

Views: 278

Answers (1)

Gumbo
Gumbo

Reputation: 655129

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">';
echo '<root>';
$hierarchy=$tree->getArray();
recursiveBuild($hierarchy[0]);
echo '</root>';
file_put_contents('file.xml', ob_get_contents());
ob_end_clean();

Upvotes: 2

Related Questions