shage Posted March 10, 2008 Share Posted March 10, 2008 i have a text file that is csv, it goes title,url,description Im trying to break it apart and loop it to make a xml <?xml version="1.0" ?> <rss version="2.0"> <channel> <title>test</title> <link>http://www.test.com/</link> <description>test</description> <item> <title>Title</title> <link>url</link> <description>descrip</description> </item> </channel> </rss> that is the code i have for the xml file, now i need help trying to loop the item part by taking and breaking the line by line down in the text file thank you Quote Link to comment https://forums.phpfreaks.com/topic/95444-csvloopxml/ Share on other sites More sharing options...
MadTechie Posted March 10, 2008 Share Posted March 10, 2008 quick simple example <?php $handle = fopen("test.csv", "r"); echo "<?xml version=\"1.0\" ? >"; //remove space after ? (added for make it format in here) echo "<rss version=\"2.0\">"; echo " <channel>"; echo " <title>test</title>"; echo " <link>http://www.test.com/</link>"; echo " <description>test</description>"; $row = 1; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { for ($c=0; $c < $num; $c++) { $title = $data[0]; $link = $data[1]; $description= $data[2]; echo " <item>"; echo " <title>$title</title>"; echo " <link>$link</link> "; echo " <description>$description</description>"; echo " </item>"; } } fclose($handle); echo " </channel>"; echo "</rss>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/95444-csvloopxml/#findComment-488654 Share on other sites More sharing options...
shage Posted March 10, 2008 Author Share Posted March 10, 2008 thank you Quote Link to comment https://forums.phpfreaks.com/topic/95444-csvloopxml/#findComment-488691 Share on other sites More sharing options...
MadTechie Posted March 10, 2008 Share Posted March 10, 2008 if this topic is solved, please click solved bottom left (i think) Quote Link to comment https://forums.phpfreaks.com/topic/95444-csvloopxml/#findComment-488702 Share on other sites More sharing options...
shage Posted March 10, 2008 Author Share Posted March 10, 2008 i was just about to say its not printing anything Quote Link to comment https://forums.phpfreaks.com/topic/95444-csvloopxml/#findComment-488708 Share on other sites More sharing options...
MadTechie Posted March 10, 2008 Share Posted March 10, 2008 oops updated <?php $handle = fopen("test.csv", "r"); echo "<?xml version=\"1.0\" ? >\n"; //remove space after ? (added for make it format in here) echo "<rss version=\"2.0\">\n"; echo " <channel>\n"; echo " <title>test</title>\n"; echo " <link>http://www.test.com/</link>\n"; echo " <description>test</description>\n"; $row = 1; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $title = $data[0]; $link = $data[1]; $description= $data[2]; echo " <item>\n"; echo " <title>$title</title>\n"; echo " <link>$link</link>\n"; echo " <description>$description</description>\n"; echo " </item>\n"; } fclose($handle); echo " </channel>\n"; echo "</rss>\n"; ?> REMEMBER the space on line 3 my csv file a1,b1,c1 a2,b2,c2 Quote Link to comment https://forums.phpfreaks.com/topic/95444-csvloopxml/#findComment-488729 Share on other sites More sharing options...
shage Posted March 10, 2008 Author Share Posted March 10, 2008 u are the man , lots of respect to you man, top notch code! Quote Link to comment https://forums.phpfreaks.com/topic/95444-csvloopxml/#findComment-488758 Share on other sites More sharing options...
MadTechie Posted March 10, 2008 Share Posted March 10, 2008 i'll take that as a solved! Quote Link to comment https://forums.phpfreaks.com/topic/95444-csvloopxml/#findComment-488768 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.