Easily Parse RSS Feeds with SimplePie
In the most recent project for Final Edge Computing, we wanted to easily parse some astronomy RSS feeds from APOD (Astronomy Picture of the Day) and Sky & Telescope. So, after googling a bit for a PHP framework that would fit my needs I came across SimplePie.
SimplePie makes dealing with a feed amazingly easy. SimplePie is just one include file which is a class built to handle RSS feeds using PHP’s various XML extensions. The class itself is very long (347KB), and yet full of a lot of useful functions dealing with RSS. Before uploading SimplePie to your server, though, make sure you meet its minimum requirements.
SimplePie’s constructor is so easy to use, in fact, all you have to do is call the constructor with 2 parameters: the feed’s URL, and where you are putting cache.
<?php
$apod = new SimplePie("http://antwrp.gsfc.nasa.gov/apod.rss", "./simplepie/cache");
?>
From here it’s really easy to manipulate the feeds items.
<div class="RSS_Header">
<div class="header_title"><a href="<?php echo $apod->get_permalink();?>"><?php echo $apod->get_title(); ?></a></div>
<span style="font-size:9px; color:#999999;"><?php echo $apod->get_description(); ?></span>
</div>
<?php foreach ($apod->get_items(0, 5) as $item): ?>
<div class="RSS_item">
<div class="title"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></div>
<?php echo $item->get_description(); ?>
</div>
<?php endforeach; ?>
<div style="padding:12px 0px;"><a href="<?php echo $apod->subscribe_feed(); ?>">Subscribe to the APOD feed</a></div>
Just wanted to throw this out there as a really easy way of dealing with RSS. I’m definitely going to continue using this on future projects.
May 18th, 2010 at 5:13:28 pm
Да, действительно. Это было и со мной. Можем пообщаться на эту тему….
Инженер-сметчик, зам. начальника СДО So, after googling a bit for a PHP framework that would fit my needs I came across SimplePie.
SimplePie makes dealing with a…