mazman13 Posted October 6, 2008 Share Posted October 6, 2008 Is it possible to convert an XML file to a .CSV. I'm waiting to store a feed in a table...and I didn't know if that was possible. Thanks Link to comment https://forums.phpfreaks.com/topic/127243-solved-can-you-convert-a-xml-file-to-a-csv/ Share on other sites More sharing options...
Barand Posted October 6, 2008 Share Posted October 6, 2008 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 Link to comment https://forums.phpfreaks.com/topic/127243-solved-can-you-convert-a-xml-file-to-a-csv/#findComment-658365 Share on other sites More sharing options...
mazman13 Posted October 6, 2008 Author Share Posted October 6, 2008 Wow. That's simple. I didn't even know you could do something like that. Thanks! Link to comment https://forums.phpfreaks.com/topic/127243-solved-can-you-convert-a-xml-file-to-a-csv/#findComment-658484 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.