3v4l.org

run code in 300+ PHP versions simultaneously
<? $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); } } } ?>

preferences:
41.09 ms | 402 KiB | 5 Q