xpersa Posted July 9, 2010 Share Posted July 9, 2010 Hello, I would like to ask you how is possible to display let's say first 10 results from a XML file. Here is a piece of my code that i use to display only the title and link to the article on uefa.com but i dont know how to get only first 10 result and not the whole file <?php $rss_file = "http://www.uefa.com/rssfeed/news/rss.xml"; $rss_feed = simplexml_load_file( $rss_file ); foreach( $rss_feed->channel->item as $item ) { echo"<a title='$item->title' href='$item->link'> $item->title</a>"; } ?> Link to comment https://forums.phpfreaks.com/topic/207293-xml-how-to-not-display-all-tags/ Share on other sites More sharing options...
harristweed Posted July 9, 2010 Share Posted July 9, 2010 <?php $rss_file = "http://www.uefa.com/rssfeed/news/rss.xml"; $rss_feed = simplexml_load_file( $rss_file ); $count=0; foreach( $rss_feed->channel->item as $item ) { while($count<10){ echo"<a title='$item->title' href='$item->link'> $item->title</a>"; $count++; } } ?> Link to comment https://forums.phpfreaks.com/topic/207293-xml-how-to-not-display-all-tags/#findComment-1083808 Share on other sites More sharing options...
xpersa Posted July 9, 2010 Author Share Posted July 9, 2010 So simple it displays 10 results but all of them are the same ... Link to comment https://forums.phpfreaks.com/topic/207293-xml-how-to-not-display-all-tags/#findComment-1083818 Share on other sites More sharing options...
harristweed Posted July 10, 2010 Share Posted July 10, 2010 of course it does! doh! <?php $rss_file = "http://www.uefa.com/rssfeed/news/rss.xml"; $rss_feed = simplexml_load_file( $rss_file ); $count=1; foreach( $rss_feed->channel->item as $item ) { echo"<a title='$item->title' href='$item->link'> $item->title</a>"; $count++; if($count >10)continue; } ?> Link to comment https://forums.phpfreaks.com/topic/207293-xml-how-to-not-display-all-tags/#findComment-1084076 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.