【发布时间】:2009-11-09 14:43:29
【问题描述】:
如何在 PHP 中创建原子提要?
【问题讨论】:
-
你做过研究吗?这是一篇相当不错的文章:ibm.com/developerworks/opensource/library/x-phpatomfeed/…
如何在 PHP 中创建原子提要?
【问题讨论】:
任何可能偶然发现此线程的人的更新:
The best PHP lib/class to generate RSS/Atom 中提出了一个非常相似的问题,它导致了许多好的 lib/roll 您自己的建议。
【讨论】:
使用library。
【讨论】:
维基百科有一个example of what an ATOM feed looks 赞。随意修改我很久以前编写的这个非常基本的 RSS 类,以创建一个非常简单的 RSS 提要:
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);
}
}
【讨论】:
O_O