Write XML code in PHP
Posted: Tue Mar 11, 2008 6:30 am
Hi, simple question: How do I create a PHP variable with this data: <?xml version="1.0"?><Tracks></Tracks>
so that in the "Overwrite file with new data" in my script, PHP will write this XML-data variable instead of the $raw_xml variable in my XML file?
One of the problems I ran into when trying this myself was that the PHP will not let my use the "" when I create a variable, but I need these quote symbols for the XML ...
Can any one help me?
so that in the "Overwrite file with new data" in my script, PHP will write this XML-data variable instead of the $raw_xml variable in my XML file?
One of the problems I ran into when trying this myself was that the PHP will not let my use the "" when I create a variable, but I need these quote symbols for the XML ...
Can any one help me?
Code: Select all
<?php
//This PHP script writes data that is sent from flash, into an XML file:------------------------------------------------
$filename = "xmldata/trackingData.xml";
$raw_xml = file_get_contents("php://input");
print $raw_xml;
//Check File Size. The size returned is in BYTES
$size = filesize($filename);
//If XML file is larger than 50KB's then make a copy.
if($size > 51200){
//Copy file with new name containing the day it was copied
$today = date("Ymd");
$newFile = "xmldata/trackingData".$today.".xml";
copy($filename, $newFile);
//-------------------------------------------------------------------------!!!!!!!!!!!!!!!!!!
//Overwrite file with new data. -----------------------------!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$fp = fopen($filename, "w");
fwrite($fp, $raw_xml); //How do I put the my XML code here? -------------------!!!!!!!!!!
fclose($fp);
} else {
//Write normally
$fp = fopen($filename, "w");
fwrite($fp, $raw_xml);
fclose($fp);
}
?>