MagpieRSS is compatible with RSS .9 through RSS 1.0, and supports the RSS 1.0's modules. (with a few exceptions)
require('rss_fetch.inc'); $rss = fetch_rss($url);
fetch_rss()
)
around the library.
parse_w3cdtf()
, for parsing W3CDTF into epoch seconds.
This makes it very simple support the varied versions of RSS simply, but forces the consumer of a RSS feed to be cognizant of how it is structured.(at least if you want to do something fancy)
Magpie parses a RSS feed into a simple object, with 4 fields:
channel
, items
, image
, and
textinput
.
$rss->channel
contains key-value pairs of all tags, without
nested tags, found between the root tag (<rdf:RDF>, or <rss>)
and the end of the document.
$rss->items
is an array of associative arrays, each one
describing a single item. An example that looks like:
<item rdf:about="http://protest.net/NorthEast/calendrome.cgi?span=event&ID=210257"> <title>Weekly Peace Vigil</title> <link>http://protest.net/NorthEast/calendrome.cgi?span=event&ID=210257</link> <description>Wear a white ribbon</description> <dc:subject>Peace</dc:subject> <ev:startdate>2002-06-01T11:00:00</ev:startdate> <ev:location>Northampton, MA</ev:location> <ev:enddate>2002-06-01T12:00:00</ev:enddate> <ev:type>Protest</ev:type> </item>
Is parsed, and pushed on the $rss->items
array as:
array( title => 'Weekly Peace Vigil', link => 'http://protest.net/NorthEast/calendrome.cgi?span=event&ID=210257', description => 'Wear a white ribbon', dc => array ( subject => 'Peace' ), ev => array ( startdate => '2002-06-01T11:00:00', enddate => '2002-06-01T12:00:00', type => 'Protest', location => 'Northampton, MA' ) );
$rss->image
and $rss-textinput
are associative arrays
including name-value pairs for anything found between the respective parent
tags.
require_once 'rss_fetch.inc'; $url = 'http://magpie.sf.net/samples/imc.1-0.rdf'; $rss = fetch_rss($url); echo "Site: ", $rss->channel['title'], "<br>\n"; foreach ($rss->items as $item ) { $title = $item[title]; $url = $item[link]; echo "<a href=$url>$title</a></li><br>\n"; }More soon....in the meantime you can check out a cool tool built with MagpieRSS, version 0.1.
coded by: kellan (at) protest.net, feedback is always appreciated.