Converting RSS to HTML

An alternative to converting your RSS feeds to JavaScript is converting them directly to HTML pages. You can load software for this purpose onto your Web server. These software packages use various programming languages on the Web server, most often PHP.


RSSlib ( is a useful package for converting RSS feeds into HTML (Figure 9.18).

Figure 9.18. RSSlib has parsers for PHP and ASP.

To install RSSlib, all you have to do is click the link and unzip the file. Then copy the unzipped files over to the directory on your server where you want to use RSSlibthe same directory as the Web page in which you want the converted RSS feed to appear (Figure 9.19).

Figure 9.19. Here's an RSSlib demo from CNET

To get similar results for the RSS feed you choose, call the PHP script rss2html.php with the URL of the RSS feed you want to display. You pass the URL of the RSS feed using the rss_url parameter. In our example, the feed comes from's top stories.

There are various ways to insert the text for the RSS feed into a Web page; here we will simply use only HTML and the <iframe> element to create floating HTML frames.

To insert the HTML for the converted feed into a Web page, first create a 300-by-400pixel floating frame without a border or scrollbar. The <iframe> element supports an <src> element, which lets you specify the source of the floating frame's content. And for the content in our example you would use this:

    rss2html.php?rss_url=    NewslineRss.xml 

Here's what it looks like in a Web page:

    <html>      <head>        <title>          The News        </title>      </head>      <body>        <h1>Here's the news from USA Today</h1>        <iframe height="300" width="400" frameborder="0" scrolling="no"        src="/books/1/255/1/html/2/rss2html.php?rss_url=        NewslineRss.xml">        </iframe>    </body>    </html> 


You can also position <iframe> elements wherever you want them in a page by using cascading style sheet (CSS) styles. Take a look at any good HTML book for the details.

The results appear in Internet Explorer, where it looks like the RSS feed's news items blend right into the page (Figure 9.20).

Figure 9.20. RSSlib displays's news in Internet Explorer.

Although the <iframe> element used to be unique to Internet Explorer, all standard browsers support it now; you can see what this page looks like in Mozilla Firefox (Figure 9.21).

Figure 9.21. RSSlib can display's news in Firefox as well.


RSS2HTML, a PHP-based software package that converts RSS to HTML, is a free PHP script from FeedForAll. You can download this script at (Figure 9.22).

Figure 9.22. FeedForAll offers a free PHP script.

To download the script, click the download link, then select the Download button. This downloads a zip file with documentation, the PHP script rss2html.php, and a sample HTML template.

To use RSS2HTML call the rss2html.php script, passing it the parameters XMLFILE, TEMPLATE, and MAXITEMS. The XMLFILE parameter gives the name of a local RSS feed file (in the same directory as the rss2html.php script) or the URL to an RSS feed; TEMPLATE gives the name of the HTML template to use when formatting the HTML (we'll use the sample template that comes with RSS2HTML), and MAXITEMS specifies the maximum number of items to use.

Here's an example; navigating to this URL displays the RSS contents of news.xml, which is the RSS feed Steve's News:    MPLATE=sample-template.html&MAXITEMS=10 

On the other hand, you may want to embed the HTML conversion of an RSS feed in a Web page, so you can use the same <iframe> technique you saw with RSSlib.

    <html>      <head>        <title>          The News        </title>      </head>            <body>        <h1>Here's the news from Steve</h1>        <iframe height="300" width="400" frameborder="0" scrolling="no"        src="/books/1/255/1/html/2/rss2html.php?XMLFILE=news.xml&TEMPLATE=sample-        template.html&MAXITEMS=10">        </iframe>    </body>    </html> 

RSS2HTML converts the RSS feed into HTML and displays it in a floating frame (Figure 9.23). Not bad.

Figure 9.23. Here's the page created with RSS2HTML.


Magpie, at, is a powerful PHP-based package that lets you parse RSS and convert it into HTML (Figure 9.24).

Figure 9.24. Magpie is an XML-based RSS parser.

You'll have to get your hands into the PHP with Magpie, because it's really an RSS parser, not an HTML formatter like the previous two packages. Magpie readsthat is, parsesan RSS feed and stores it in a PHP object, and you're responsible for unpacking the feed's data and formatting it as you want.

Here's a little PHP to read the example feed from's top stories. You start PHP scripts with <?php, and in this case, the Magpie script is included.

    <?php      require '';            .            .            . 

Now you can call the Magpie PHP function fetch_rss, passing it the URL of the RSS feed you want to grab.

    <?php      require '';             $url = '';      $rss = fetch_rss($url);            .            .            . 

This code reads the RSS feed and stores it in the PHP variable $rss. You can display the title of the RSS feed this way:

    <?php      require '' ;      $url = '';      $rss = fetch_rss($url);            echo $rss->channel['title'], "<br>";            .            .            . 

You can also use a PHP foreach loop to display a hyperlink for the items in the feed, each on its own line.

    <?php      require '';               $url = '';      $rss = fetch_rss($url);             echo $rss->channel['title'], "<br>";               foreach ($rss->items as $item) {        $t = $item['title'];        $u   = $item['link'];        echo "<a href=$u>$t</a><br>";      }    ?> 


If you don't know PHP, you can use this PHP script to convert RSS to HTML using Magpiejust change the feed's URL to the URL of the feed you want to use.

Now, when you use your browser to navigate to this script, called news.php in our example, you'll see your feed in HTML form (Figure 9.25). This is assuming the Magpie PHP script is in the same directory as the news.php script.

Figure 9.25. Here's the feed from Magpie's output of the news.php script.

You can also embed news.php in another Web page using floating frames as before.

    <html>      <head>        <title>          The News        </title>      </head>      <body>        <h1>Here's the news from USA Today</h1>        <iframe height="300" width="400" frameborder="0"        scrolling="no"         src="/books/1/255/1/html/2/news.php">        </iframe>    </body>    </html> 

The results of this HTML appear on a page in Internet Explorer, where you can see the feed that Magpie grabbed for you (Figure 9.26).

Figure 9.26. Created with Magpie, the top-stories feed appears in Internet Explorer.


The DOMit software package has a parser that can put RSS in XML DOM (Document Object Model) form (Figure 9.27).

Figure 9.27. DOMit Uses a DOM XML parser.

XML DOM is beyond the scope of this book, but if you're an accomplished XML and PHP person, DOMit may be the package for you. The DOMit RSS parser requires the DOMit XML parser, but you can download it for free at

You can see the DOMit RSS package at work in an example at (Figure 9.28).

Figure 9.28. DOMit's testing interface is easy to use.

Select an RSS feed to convert to HTML, or enter the URL of a feed and click the Parse RSS button to give you the RSS feed converted to HTML (Figure 9.29).

Figure 9.29. Here's the RSS parsed by DOMit.

Other PHP-based RSS Converters

RSSProcessor is an RSS converter ($79.99) that you can find at (Figure 9.30).

Figure 9.30. Sciento includes a link to view a site that uses RSSProcessor.

RSSProcessor also converts multiple RSS feeds into Web page content.

Secrets of RSS
Secrets of RSS
ISBN: 0321426223
EAN: 2147483647
Year: 2004
Pages: 110

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: