PGFeed is a caching PHP parser for RSS and Atom feeds. It uses PHP’s XMLReader functions and so will only run under PHP 5.



require "PGFeed.php";
$p = new PGFeed;

$source = "somefeed";
$channel = $p->getChannel(); // gets data about the feed as a whole
echo $channel["title"];      // prints the title of the feed

$items = $p->getItems();     // gets news items

// prints the linked title for each item                                        
foreach ($items as $i) {                                                        
  echo "<a href=\"" . $i['link'] . "\">" . $i['title'] . "</a><br />";           

$p->dump();                  // prints out array structure of parse

There are four parameters that may altered. These are:

  1. strip – removes all markup from output, including images. Default is off (0). Turn it on with stripMarkup().
  2. returns – controls how many items are returned for a feed. Default is 6. This may be changed by using the setReturns(int) function.
  3. error-reporting – controls whether error messages are visible. Default is off (0). Turn it on with reportErrors().
  4. caching – Sets the time limit for caching. Default is 7200 (2 hrs.). Change this with setCacheTime(int) or use dontCache().

The above options may be set all at once by using the following abbreviated form:


This would create a parser that strips markup, returns 3 items, does not show error messages, and continues to use a cached copy of a feed for 24 hrs.

Finally, if you would like to customize the error message generated when an exception is thrown, you can do so as follows:

$p->setErrorMessage("my custom error message");


Notes on Flickr

PGFeed makes Flickr images available in three forms: full, thumbnail, and square thumbnail. Full images can be of any size. The data for a full image is returned as fullImageURL, fullImageHeight, and fullImageWidth. Thumbnail images have the same aspect ratio as the full image, but their longest side is 100 pixels. PGFeed returns thumbnail data as in the code sample below. Finally, square thumbnails are 75 pixels on a side. Their data is returned as squareThumbnailURL, &c.

Besides the data regarding the image itself, a Flickr feed contains metadata such as: pubDate, author, caption. You can use the dump() function to see all of the data that is returned.

Make sure you do not use the strip option if you are parsing a Flickr feed: this will make the images go away.

// displays linked thumbnails from a Flickr feed
$items = $p->getItems();
foreach ($items as $i) {                                                        
  echo "<a href=\"" . $i['link'] . "\"><img src=\"" .                        
        $i['thumbnailURL'] . "\" height=\"" .                                
        $i['thumbnailHeight'] . "\" width=\"" .                              
        $i['thumbnailWidth'] . "\" /></a><br/>";                            


© 2008 Ron Gilmour

This software is distributed under the terms of the GNU General Public License. A copy of this license is bundled with the software.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Print Friendly