ak111in Posted March 31, 2012 Share Posted March 31, 2012 xml file: <PRICES> <PRICE> <WIC>HDE0AAFGRBOX</WIC> <STOCK>100+</STOCK> <MY_PRICE>219.00</MY_PRICE> </PRICE> </PRICES> php file: <? $filexml='stock.xml'; if (file_exists($filexml)) { $xml = simplexml_load_file($filexml); $f = fopen('stock.csv', 'w'); foreach($xml->PRICES->PRICE as $price) { fputcsv($f, get_object_vars($price),',','"'); } fclose($f); } ?> Error: Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\stock.php on line 6 Please help with this. Link to comment https://forums.phpfreaks.com/topic/260064-help-converting-xml-to-csv/ Share on other sites More sharing options...
q11we Posted March 31, 2012 Share Posted March 31, 2012 as PRICES is the root element it is already loaded when you load xml file. so try using foreach($xml->PRICE as $price) hope this will help Link to comment https://forums.phpfreaks.com/topic/260064-help-converting-xml-to-csv/#findComment-1332996 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.