PHP code for xml parser (rss)

I’ve been looking for PHP code to read RSS feed from blog. It is a simple XML reader code actually and can use a ready class available on the net.

I found this class magpierss which is quite easy to use. You just need to include one file in your code and that one file will call few other library files.

The PHP code you need to use to get the XML data is just like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
 
define('MAGPIE_DIR', 'rssreader/');
require_once(MAGPIE_DIR.'rss_fetch.inc');
 
$url = 'http://www.azwan.net/blog/feed/';
 
if ( $url ) {
	$rss = fetch_rss( $url );
	echo "Channel: " . $rss->channel['title'] . "<p>";
	echo "<ul>";
	foreach ($rss->items as $item) {
		$href = $item['link'];
		$title = $item['title'];
		echo "<li><a href=$href>$title</a></li>";
	}
	echo "</ul>";
}
?>

Download code

Leave a Reply

Your email address will not be published. Required fields are marked *