Code: Select all
<?php
//variables
$raw_xml = file_get_contents('php://input');
$stories = file_get_contents("Stories.xml");
//ignore the document type
$raw_xml = preg_replace("/\<\?xml.*?\>/", '', $raw_xml);
$raw_xml = trim($raw_xml);
//add new story
$stories = preg_replace("</stories>", "$raw_xml </stories>", $stories);
//open the file for writing
$fp = fopen("Stories.xml", "wb");
//write to file
fwrite($fp, $stories);
fclose($fp);
//send to flash
print $stories;
?>Seems like an php-xml append script should be fairly easy/common, but I haven't found anything online except for the simple script on Kirupa.com, which won't work if two instances of the xml file are open at the same time. (one of the stories gets deleted in that case).
Thanks for your help!