Example use of Magpie RSS to add a feed to your php page
Download magpie rss and upload to your web storage – have a look at the instructions for configuring caching etc. If you want to sort the output – then include the following function on your page
function compare_date($a, $b)
{
return strcmp($b['date_timestamp'], $a['date_timestamp']);
}
# sort alphabetically by name
?>
Then in the part of your page you want the rss results to be shown – replacef @url with the feed url
require_once('magpierss/rss_fetch.inc');
$url = 'http://rss.thisis.co.uk/ThisIsSouthWales/StarNews.rss' ;
$rss = fetch_rss( $url );
echo "“;
echo $rss->channel['title'] . “
“;
echo “
- “;
- $title
$num_items=5;
usort($rss->items, ‘compare_date’); // Only if you want the items sorted
$items = array_slice($rss->items, 0, $num_items);
foreach ($items as $item) {
$href = $item['link'];
$title = $item['title'];
$desc = str_replace(‘
‘,”,$item['description']);
$dt = $item['pubdate'];
echo “
$desc updated $dt “;
}
echo “
“;?>
Hey presto – you have implemented a feed on your page where the source is cached and the content is searchable – unlike java rss feeds.
I’ve left you to come up with the table / div container for the results!
[...] The feed is now live on Where In Llanelli web site giving feeds from the Llanelli Star and BBC Local information for South Wales. The page with the rss feed in is live on their news page although this is undergping a “redesign” – new look is at News2 Source code sample (partial) [...]
Pingback by svekweb.co.uk » Magpie rss feed now live — October 18, 2007 @ 10:21 am