Jump to content

[SOLVED] Can you convert a XML file to a .CSV


mazman13

Recommended Posts

sample

<?php
$str = '<rss>
<channel>
</channel>
<item>
       <a>aaa</a>
       <b>bbb</b>
       <c>ccc</c>
</item>
<item>
       <a>ddd</a>
       <b>eee</b>
       <c>fff</c>
</item>
<item>
       <a>ggg</a>
       <b>hhh</b>
       <c>jjj</c>
</item>
</rss>';

$xml = simplexml_load_string($str);

$fp = fopen('my.csv', 'w');
foreach ($xml->item as $i)
{
    fputcsv($fp, get_object_vars($i));
}
fclose($fp);
?>

my.csv-->

aaa,bbb,ccc
ddd,eee,fff
ggg,hhh,jjj

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.