Limit RSS feed results

This is a follow on from the previous entry, the rss feed before returned 15 entries but lets say you only wanted maybe the last 3 entries. This example can help

<?php
require_once ‘rss_fetch.inc’;
//change to your rss feed
$url = “http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/football/rss.xml“;
//number of items to display
$num_items = 3;
$rss = fetch_rss($url);

echo “Site: “, $rss->channel[‘title’], “<br>”;
echo “<ul>”;

$items = array_slice($rss->items, 0, $num_items);

foreach ($items as $item )
{
 $title = $item[title];
 $url   = $item[link];
 $description = $item[‘description’];
 echo “<li><a href=$href>$title</a><br />$description</li>”;
}
 
echo “</ul>”;
?>

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*