PHP - Getting an XML file that is echoed in another PHP file, then saving the echoed XML output to the server -
i have php file - called xml_generate.php
- creates dom object , echoes @ end.
lets looks this:
header("content-type: text/xml"); $dom = new domdocument('1.0'); $node = $dom->createelement('foo'); $root = $dom->appendchild($node); $node = $dom->createelement('bar'); $new_node = $root->appendchild($node); echo $dom->savexml();
i'm accessing file jquery , displaying content on client-side. actual xml_generate.php creates dom dynamically database.
however, want have php file create backup of xml generated generate_xml.php , save server.
so, need somehow access xml document (the 1 dynamically created in xml_generate.php).
i've tried a few different functions xml xml_generate.php, instance:
$xml = http_get('xml_generate.php');
,
$xml = file_get_contents('xml_generate.php');
as including first file (include('xml_generate.php')
, trying access $dom
variable in file).
but can't seem right. ideas on best approach this?
you use output buffering, buffer data sent output stream, , retrieve after including script:
ob_start(); include "xml_generate.php"; $xml = ob_get_contents(); ob_end_clean();
make sure catch errors @"xml_generate.php" though, or these buffered , you'll end invalid xml backup.
Comments
Post a Comment