PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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?
<?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);
}
?>
That is both uglier and slower and contains more characters to write.
That is however the better way of doing it because,
You have the same problem with single quote strings. The minute the string contains a single quote, it will break. e.g. $foo = 'Welcome to Steve's party'.
PHP variables are not parsed in single quote strings, aka you won't be able to do $foo = "Welcome to $location.";
That is both uglier and slower and contains more characters to write.
That is however the better way of doing it because,
You have the same problem with single quote strings. The minute the string contains a single quote, it will break. e.g. $foo = 'Welcome to Steve's party'.
PHP variables are not parsed in single quote strings, aka you won't be able to do $foo = "Welcome to $location.";
For the sake of clarity i think its good that you cannot use variables in single quotes and i also think you shouldnt be able to in double its a bad habbit