How do I go about creating an atom feed in PHP?
Asked
Active
Viewed 2,992 times
3
-
3Have you done any research? This is a pretty decent article: http://www.ibm.com/developerworks/opensource/library/x-phpatomfeed/index.html – Ben Everard Nov 09 '09 at 14:45
3 Answers
3
An update for anyone that may stumble upon this thread:
A very similar question was asked in The best PHP lib/class to generate RSS/Atom and it lead to a number of good lib/roll your own recommendations.

Community
- 1
- 1

labratmatt
- 1,821
- 2
- 20
- 21
-1
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
- 3,255
- 6
- 34
- 40
-
You aren’t escaping virtually anything! What if there is a literal tag in the item title or description? The output will be borked. `O_O` – Alan H. Jun 15 '11 at 23:39