PHP RSS Tutorial

PHP Rss Feeds With Magpie

This tutorial shows how to use Magpie to parse an rss feed. If you need to know how to install Magpie in 30 seconds, please see this PHP RSS Feed tutorial.

Here is how php parses the rss feed. We require the file rss_fetch.inc so that we can parse the feed. Then, we set which RSS feed url is used for the feed. Then, the rss feed url is run through the fetch_rss() function located in the Magpie installation. Then, Magpie returns an array called $items and that data is parsed. Within the foreach loop, all data for each rss feed entry is printed.

require('magpie/rss_fetch.inc');
	
	$url = 'http://vancouver.en.craigslist.ca/cta/index.rss';
	$rss = fetch_rss($url);

foreach ($rss->items as $item ) {
	$title = $item[title];
	$url   = $item[link];
	$description   = $item[description];
	$date = $item['dc']['date'];
	echo "<a href='".$url."'>".$title."</a>-".$description."-".$date."<br>";
}


More Code Samples:
Parse Multiple URLs From RSS Feed Part 1
Parse Multiple URLs RSS Feed Into a Table Part 2