Jump to content

[Solved]How to limit items that come in with SimpleXML?


speculumcm

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...