speculumcm Posted June 12, 2010 Share Posted June 12, 2010 Hello everyone, Might be this is a dumb question but I'm trying to use SimpleXML extension to get some RSS Feeds come in and displaying in a website, is there a way to limit the amount of RSS Feeds come in?The script that I'm using is: <?phpfunction getFeed($feed_url) { $content = file_get_contents($feed_url); $x = new SimpleXmlElement($content); echo "<ul>"; foreach($x->channel->item as $entry) { echo "<li><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>"; } echo "</ul>";}?> The script works good but don't know how to limit the feeds come in, any idea?Thanks Link to comment Share on other sites More sharing options...
boen_robot Posted June 12, 2010 Share Posted June 12, 2010 You mean the items that come in?If so, I'd suggest using a for instead of a foreach, like: $limit = 5; for ($i = 0; $i<$limit; $i++) { $entry = $x->channel->item[$i]; echo "<li><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>"; } In this case, this would show the first 5 feeds. Replace $limit with whatever you want the actual limit to be. Link to comment Share on other sites More sharing options...
speculumcm Posted June 13, 2010 Author Share Posted June 13, 2010 boen_robot, you are solid ROCKS! Thank you so much the script works like a charm! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.