hyster Posted February 2, 2013 Share Posted February 2, 2013 i followed the guide on this site for the rss tutorial. i altered it to what i wanted but i can not get it to loop. it will only display the first line. the tutorial says to use echo <<<EOF but they caused the script to not work. any help would be gratefull. <?php $xml = new SimpleXMLElement('http://api.wot-blackdeath.ru/wot-news/eu/wot-news.xml', null, true); echo "<table border='1'>" ; foreach($xml as $data){ // loop through our xml ?> <tr><td> <?php echo $data->title ?></td></tr> <tr><td> <?php echo $data->description ?></td></tr> <tr><td> <?php echo $data->link ?></td></tr> <tr><td> <?php echo $data->pubDate ?></td></tr> <?php } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/273937-php-rss-tutorial/ Share on other sites More sharing options...
requinix Posted February 2, 2013 Share Posted February 2, 2013 foreach($xml as $data){ foreach what part of the $xml? Link to comment https://forums.phpfreaks.com/topic/273937-php-rss-tutorial/#findComment-1409652 Share on other sites More sharing options...
codebyren Posted February 2, 2013 Share Posted February 2, 2013 The xml looks like it could contain any number of <channel> entries. Each of these channels has its own title, description etc. as well as any number of <item> entries which also have their own title, description etc. So, going by the code you have so far, it might read better as: <?php foreach ($xml as $channel) : ?> Then you could access the CHANNEL info like this: <?php echo $channel->title; ?> <?php echo $channel->description; ?> etc... You could then cycle through each $channel's <item> entries: <?php foreach ($channel->item as $item) : ?> After which you could access the ITEM info like this: <?php echo $item->title; ?> <?php echo $item->description; ?> etc... Hope that clears things up a little. Link to comment https://forums.phpfreaks.com/topic/273937-php-rss-tutorial/#findComment-1409677 Share on other sites More sharing options...
hyster Posted February 2, 2013 Author Share Posted February 2, 2013 i carnt get my head round this lol. the xml im reading is laid out like this <channel> <item> <title>data</title> <description>data</description> <link>data</link> <pubDate>data</pubDate> <guid>data</guid> </item> <item> <title>data</title> <description>data</description> <link>data</link> <pubDate>data</pubDate> <guid>data</guid> </item> <channel> using following code i get the php to loop the correct amount of times ( but the echo'd value is "item" <?php $xml = new SimpleXMLElement('http://api.wot-blackdeath.ru/wot-news/eu/wot-news.xml', null, true); echo "<table border='1'>" ; foreach($xml->channel->item as $data => $value){ ?> <tr><td>1</td><td><b> <?php echo $data ?></b></td></tr> <tr><td>2</td><td> <?php echo $data ?></td></tr> <tr><td>3</td><td> <?php echo $data ?></td></tr> <tr><td>4</td><td> <?php echo $data ?></td></tr> <tr><td>5</td><td> <?php echo $data ?></td></tr> <?php } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/273937-php-rss-tutorial/#findComment-1409685 Share on other sites More sharing options...
requinix Posted February 2, 2013 Share Posted February 2, 2013 Well... yeah. That's the key of the "array" you're looping over. The name of the node. You don't want the name. Link to comment https://forums.phpfreaks.com/topic/273937-php-rss-tutorial/#findComment-1409689 Share on other sites More sharing options...
Barand Posted February 2, 2013 Share Posted February 2, 2013 foreach ($xml->channel->item as $item) { echo '<p>' . $item->description . '</p>'; // etc } Link to comment https://forums.phpfreaks.com/topic/273937-php-rss-tutorial/#findComment-1409709 Share on other sites More sharing options...
hyster Posted February 2, 2013 Author Share Posted February 2, 2013 thanks once again barand. ur a star Link to comment https://forums.phpfreaks.com/topic/273937-php-rss-tutorial/#findComment-1409742 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.