<?
$filexml='data.xml';
preg_match("/([a-zA-Z0-9_-]+).([a-zA-Z0-9]+)/", $filexml, $extension);
//$timestamp = date("Y-m-d_H:i:s");
$timestamp = time(); //$timestamp gets current time
$myFile = data.$timestamp.".".$extension[2];
echo $myFile;
file_put_contents($myFile, file_get_contents("input.txt"));
$mycsvFile = "orderData.".$timestamp.".csv"; // timestamp to file name
echo $mycsvFile;
if (file_exists($myFile))
{
$xml = simplexml_load_file($myFile);
$f = fopen($mycsvFile, 'w'); // open and write to file
createCsv($xml, $f);
fclose($f);
}
function createCsv($xml,$f)
{
foreach ($xml->children() as $item)
{
$hasChild = (count($item->children()) > 0)?true:false;
if( ! $hasChild)
{
$put_arr = array($item->getName(),$item);
fputcsv($f, $put_arr ,',','"');
}
else
{
createCsv($item, $f);
}
}
}
?>
Output for 8.0.13
Fatal error: Uncaught Error: Undefined constant "data" in /in/ARBW5:6
Stack trace:
#0 {main}
thrown in /in/ARBW5 on line 6
Process exited with code 255.
Output for 7.3.32 - 7.3.33, 7.4.33
Warning: Use of undefined constant data - assumed 'data' (this will throw an Error in a future version of PHP) in /in/ARBW5 on line 6
data1400832854.xml
Warning: file_get_contents(input.txt): failed to open stream: No such file or directory in /in/ARBW5 on line 8
Warning: file_put_contents(data1400832854.xml): failed to open stream: Read-only file system in /in/ARBW5 on line 8
orderData.1400832854.csv
Output for 7.2.6
Warning: Use of undefined constant data - assumed 'data' (this will throw an Error in a future version of PHP) in /in/ARBW5 on line 6
data1400832854.xml
Warning: file_get_contents(): open_basedir restriction in effect. File(input.txt) is not within the allowed path(s): (/tmp:/in) in /in/ARBW5 on line 8
Warning: file_get_contents(input.txt): failed to open stream: Operation not permitted in /in/ARBW5 on line 8
Warning: file_put_contents(): open_basedir restriction in effect. File(data1400832854.xml) is not within the allowed path(s): (/tmp:/in) in /in/ARBW5 on line 8
Warning: file_put_contents(data1400832854.xml): failed to open stream: Operation not permitted in /in/ARBW5 on line 8
orderData.1400832854.csv
Warning: file_exists(): open_basedir restriction in effect. File(data1400832854.xml) is not within the allowed path(s): (/tmp:/in) in /in/ARBW5 on line 13
Output for 7.2.0
Warning: Use of undefined constant data - assumed 'data' (this will throw an Error in a future version of PHP) in /in/ARBW5 on line 6
data1400832854.xml
Warning: file_get_contents(input.txt): failed to open stream: No such file or directory in /in/ARBW5 on line 8
Warning: file_put_contents(data1400832854.xml): failed to open stream: Permission denied in /in/ARBW5 on line 8
orderData.1400832854.csv
Output for 7.1.20
Notice: Use of undefined constant data - assumed 'data' in /in/ARBW5 on line 6
data1400832854.xml
Warning: file_get_contents(): open_basedir restriction in effect. File(input.txt) is not within the allowed path(s): (/tmp:/in) in /in/ARBW5 on line 8
Warning: file_get_contents(input.txt): failed to open stream: Operation not permitted in /in/ARBW5 on line 8
Warning: file_put_contents(): open_basedir restriction in effect. File(data1400832854.xml) is not within the allowed path(s): (/tmp:/in) in /in/ARBW5 on line 8
Warning: file_put_contents(data1400832854.xml): failed to open stream: Operation not permitted in /in/ARBW5 on line 8
orderData.1400832854.csv
Warning: file_exists(): open_basedir restriction in effect. File(data1400832854.xml) is not within the allowed path(s): (/tmp:/in) in /in/ARBW5 on line 13
Notice: Use of undefined constant data - assumed 'data' in /in/ARBW5 on line 6
data1400832854.xml
Warning: file_get_contents(input.txt): failed to open stream: No such file or directory in /in/ARBW5 on line 8
Warning: file_put_contents(data1400832854.xml): failed to open stream: Permission denied in /in/ARBW5 on line 8
orderData.1400832854.csv