How do I go about creating an atom feed in PHP?
A:
Wikipedia has an example of what an ATOM feed looks like. Feel free to modify this very basic RSS class that I wrote a long while ago to create a very simple RSS feed:
class RSSFeed
{
var $feedHeader;
var $feedItems;
/* Class Constructor */
function RSSFeed()
{
//do some contruction
$this->feedHeader = '';
$this->feedItems = '';
}
function setFeedHeader($title, $link, $description, $copyright, $lastBuildDate, $ttl)
{
$this->feedHeader = '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel>';
$this->feedHeader .= '<title>'.$title.'</title>';
$this->feedHeader .= '<link>'.$link.'</link>';
$this->feedHeader .= '<description>'.$description.'</description><copyright>'.$copyright.'</copyright>';
$this->feedHeader .= '<language>en-GB</language><lastBuildDate>'.$lastBuildDate.' GMT</lastBuildDate><ttl>'.$ttl.'</ttl>';
}
function pushItem($title, $link, $description, $pubDateTime)
{
$item = '<item><title>' . htmlentities(stripslashes($title)) . '</title>';
$item .= '<link>' . $link . '</link>';
$item .= '<guid>' . $link . '</guid>';
$item .= '<description>' . htmlentities(stripslashes($description)) . '</description>';
$item .= '<pubDate>' . $pubDateTime . ' GMT</pubDate></item>';
$this->feedItems = $item . $this->feedItems;
}
function writeOutFeed($path)
{
$file = fopen($path, "w");
fputs($file, $this->feedHeader);
fputs($file, $this->feedItems);
fputs($file, '</channel></rss>');
fclose($file);
}
}
MalphasWats
2009-11-09 14:49:08
A:
An update for anyone that may stumble upon this thread:
A very similar question was asked in http://stackoverflow.com/questions/182510/what-is-the-best-php-lib-class-to-generate-rss-atom and it lead to a number of good lib/roll your own recommendations.
labratmatt
2010-06-23 17:49:13