你如何生成RSS提要?

the*_*int 6 php rss

我自己从来没有这样做过,而且我从来没有订过饲料,但似乎我要创建一个,所以我很想知道.对我来说唯一明显的方法是,当使用新项目(博客文章,新闻项目等)更新系统时,应该将新元素写入rss文件.或者有一个脚本,每天检查几次系统更新,并写入rss文件.尽管如此,可能还有更好的方法.

而且,如果添加新元素,是否应删除旧元素?

编辑:我应该提到,我正在使用PHP,特别是使用CodeIgniter,使用mySQL数据库.

Zor*_*che 6

对于PHP我使用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);
Run Code Online (Sandbox Code Playgroud)


Dre*_*son 3

我认为答案是让 RSS 提要只不过是数据的另一种视图。这意味着您的 rss feed 只是数据库中数据的 xml 表示形式。然后,读者将能够点击该特定 URL 并获取应用程序中的当前信息。