RSS (Really Simple Syndication) Viewer

29-Aug-2006: Update
I have made some improvements to the RSS Viewer which are worth posting. First, I've drastically simplified the code, allowing the XML parsing and output of the RSS items to occur inline. If you compare the new script (~2K) to the old script (~4K), you will see how many unnecessary steps I was taking. Oh, well... you live and you learn.

Second, many RSS feeds are presently inserting HTML tags inside the item description (to allow images, etc. to be included in the content). I've included code which gives the user the option of whether or not to display the HTML. See below for more details.

      RSS feeds have become a popular and inexpensive way for webmasters to incorporate more dynamic content on their pages without having to bother writing and editing the content themselves. All of the major news wire serives like Associated Press and Reuters, as well as most popular blog pages offer syndication of their content through RSS feeds, usually at no cost. This is accomplished by publishing clippings of the content in a highly structured XML document. Here is what a typical RSS page looks like. Keeping the content up-to-date becomes the responsibility of the publisher. Our only job, then, is to parse the XML document for the pertinent information, i.e. the titles, links, and descriptions for each item.

      That's where I come in. As an alternative to the numerous news aggregators that will collect selected RSS feeds for you, I wanted to provide a tool that will allow web authors embed RSS feeds directly into their pages. Once you've included the file rssviewer.php, adding the following line of code to a PHP page:

<?php printStoriesRSS("http://feeds.engadget.com/weblogsinc/engadget", 2); ?>

Will produce the following output:


Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/.nicholas/bsterne/sternefamily.net/brandon/functions.php:104 Stack trace: #0 /home/.nicholas/bsterne/sternefamily.net/brandon/functions.php(104): SimpleXMLElement->__construct('') #1 /home/.nicholas/bsterne/sternefamily.net/brandon/articles/rssviewer.php(32): printStoriesRSS_new('http://feeds.en...', 2) #2 {main} thrown in /home/.nicholas/bsterne/sternefamily.net/brandon/functions.php on line 104