您如何生成 RSS 提要? [英] How do you generate an RSS feed?
问题描述
我自己从未做过,也从未订阅过 Feed,但似乎我将不得不创建一个,所以我想知道.对我来说似乎很明显的唯一方法是,当系统用新项目(博客文章、新闻项目等)更新时,应该将一个新元素写入 rss 文件.或者,有一个脚本可以每天检查系统更新几次并写入 rss 文件.不过,可能有更好的方法.
I've never done it myself, and I've never subscribed to a feed, but it seems that I'm going to have to create one, so I'm wondering. The only way that seems apparent to me is that when the system is updated with a new item (blog post, news item, whatever), a new element should be written to the rss file. Or alternatively have a script that checks for updates to the system a few times a day and writes to the rss file is there is. There's probably a better way of doing it though.
此外,是否应该在添加新元素时删除旧元素?
And also, should old elements be removed as new ones are added?
编辑:我应该提到,我正在使用 PHP,特别是使用带有 mySQL 数据库的 CodeIgniter.
Edit: I should have mentioned, I'm working in PHP, specifically using CodeIgniter, with a mySQL database.
推荐答案
对于 PHP,我使用 feedcreatorhttp://feedcreator.org/
For PHP I use feedcreator http://feedcreator.org/
<?php define ('CONFIG_SYSTEM_URL','http://www.domain.tld/');
require_once('feedcreator/feedcreator.class.php');
$feedformat='RSS2.0';
header('Content-type: application/xml');
$rss = new UniversalFeedCreator();
$rss->useCached();
$rss->title = "Item List";
$rss->cssStyleSheet='';
$rss->description = 'this feed';
$rss->link = CONFIG_SYSTEM_URL;
$rss->syndicationURL = CONFIG_SYSTEM_URL.'feed.php';
$articles=new itemList(); // list of stuff
foreach ($articles as $i) {
$item = new FeedItem();
$item->title = sprintf('%s',$i->title);
$item->link = CONFIG_SYSTEM_URL.'item.php?id='.$i->dbId;
$item->description = $i->Subject;
$item->date = $i->ModifyDate;
$item->source = CONFIG_SYSTEM_URL;
$item->author = $i->User;
$rss->addItem($item);
}
print $rss->createFeed($feedformat);
这篇关于您如何生成 RSS 提要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!