tags:

views:

294

answers:

6
+1  Q: 

RSS feeds in PHP

Just wondering if someone could suggest a PHP library that would allow me to read the data of an RSS feed and write it to a MySQL database. Also, if possible, provide a link to documentation about how to do this?

Thanks

+2  A: 

Simplepie is probably the most popular PHP RSS library.

Daff
A: 

Magpie is an excellent RSS library

http://magpierss.sourceforge.net/

There's an example of using it here: http://www.olate.co.uk/articles/view.php?id=214

Once you've used Magpie to grab an RSS feed you can store it in a string a save to a DB as you would with any other string.

Steve Claridge
Magpie is severely outdated and is quite hard to use.
Ryan McCue
+2  A: 

Reading data that simple is something you could use simplexml for.

http://www.ibm.com/developerworks/library/x-simplexml.html

From there you can see how easy it is to grab the data, instead of displaying, you store in a database.

Gotchas: badly formatted rss (see above tut) different flavours of rss (ditto) evil values in the rss - it's foreign data and should be handled with suspicion dependency on allow_url_fopen - maybe use cURL

Cups
This is exactly what I do, I use cURL to fetch the feeds and cache them every x hours. And I use SimpleXML to extract the relevant information.
Sbm007
+5  A: 

RSS is a pretty simple format - there is no great need to use a separate library.

I'd just use simplexml, because I don't wanna spend the effort learning another library, and keeping up with its development.

Here is a simple PHP script for showing the latest Stackoverflor posts with simplexml:

<?php
$rss = simplexml_load_file('http://stackoverflow.com/feeds');
?>
<h1><?php echo $rss->title; ?></h1>
<ul>
<?php
foreach($rss->entry as $e) {
    echo "<li><a href=\"".$e->link['href']."\">";
    echo $e->title; 
    echo "</a></li>\n";
}    
?>
</ul>
gnud
A: 

You can also give XPath a try, pretty simple to use.

Kyle J. Dye
A: 

SimplePie is definitely the way to go. You can download and parse an RSS feed in under 10 lines of code. There is a tutorial here that shows you how.

Phyxx