Really Simple RSS

The newsboxes on the site are live, all in about a dozen lines of PHP. The backend to this is the extremely useful Magpie RSS parser tool ( ) which, at its simplest level, takes an RSS URL and spits out a code object representing the feed.

Since the whole point of this site is to be self-documentary, here's how I've done it:

1) Download magpieRSS (in this case, v0.52) from sourceforge.
2) Unzip it (tar -xvzf) into the web directory
3) Symlink around the version number (ln -s magpierss-0.5.2 magpie)
4) Edit the file to set up caching - this takes a few DEFINE statements that you can add anywhere in the code path, but that I tend to add in the "constants" section of the file in Magpie:
define('MAGPIE_DEBUG',TRUE); #this one's optional
define('MAGPIE_CACHE_DIR',MAGPIE_DIR . '/cache');

5) Create the specified cache dir and make it writeable by the webserver.
6) Use the following function to generate really simple newsboxes:


function rssbox($feedurl,$items=5) {
static $boxnum=0;
if($rss->ERROR) { return("<p>RSS error: $rss->ERROR</p>"); }
$ret=("<div class=\"rssbox\" id=\"rssbox$boxnum\">
<div class=\"rsstitle\"><a href=\"".
for($i=0;(($i+1)<count($rss->items) && ($i<$items));$i++) {
$ret.=("<div class=\"rssstory\"><a href=\"".


7) and call it with print(rss($rssurl));

8) Style as desired in CSS :)

Of course it's not nearly so powerful as my rss viewer app ( ) , but then that produces some semantically horrible code at the moment, so rewriting it in full will be one of the objectives for this site.
Posted by parsingphase, 2004-04-08 11:56

Anonymous user




I'm currently available for contract work in London as a Senior PHP Developer. Contact me for a CV, rates, or a chat.

Twitter @parsingphase
Github parsingphase
LinkedIn Richard George
Flickr parsingphase