Jump to content

Help converting XML to CSV


ak111in

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.