如何在 PHP 中创建原子提要?
问问题
2808 次
3 回答
3
任何可能偶然发现此线程的人的更新:
在生成 RSS/Atom 的最佳 PHP 库/类中提出了一个非常相似的问题,它导致了许多好的库/滚动您自己的建议。
于 2010-06-23T17:49:13.147 回答
0
使用库。
于 2009-11-09T14:47:42.847 回答
-2
维基百科有一个 ATOM 提要的例子。随意修改我很久以前编写的这个非常基本的 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);
}
}
于 2009-11-09T14:49:08.953 回答