... using Blosxom to retrace my steps

tstigers.net - Home :: Entries :: Feeds :: Photos
April 2024
Sun Mon Tue Wed Thu Fri Sat
 
       


Sun, 25 Nov 2007

Creating a feeds page with PHP

Fed up with dysfunctional downloadable scripts, I sat down and wrote some code to fetch and display my feeds. No need to look at the K2 sidebar widget.

Turns out that PHP has all you need - and what you need is no more than one specialised function: simplexml_load_file(). Any object created with this function has properties which are the XML nodes, e.g. ->channel, ->channel->item->title or ->item->link (depending, of course, on the structure of the XML file in question). Throw in a few control structures (if, foreach) and string functions (strlen, substr) and you're done. Tweaking the stylesheet so the output of my script is displayed nicely took me more time than writing and testing the script. I found the relevant chapter of the PHP manual at PHPBuilder very useful.

Since del.icio.us publishes an RDF feed, not a "normal" RSS one, I had to come up with 2 different versions of my "fetchFeed" function. (In an RDF file, an "item" is a child of the document - in an RSS file, it's a child of a "channel", which in turn is a child of the document.) Adapting the function to Atom or whatever is probably easy, too.

Posted on 25 Nov 2007 at 15:59 in /technology/internet. -- Permalink


Powered by Blosxom RSS feed: /index.rss