3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<? $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 5.4.0 - 7.1.0
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
Output for 4.3.0 - 5.3.29
<? $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); } } } ?>