简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM