Creating an RSS feed for a web site, PHP

From Help With Kumu Wiki

Jump to: navigation, search

[edit] Alerting Internet Explorer 7, Firefox and Safari About RSS feed

The following line should be added to the head of your web pages:

<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="/index.rss.php" />

[edit] Implementation Example in PHP5

Here is how the RSS feed for this site's main page is created: http://kumu.brocku.ca/index.rss.php

<source lang="php"> <?PHP /**

  • MySQL connection is made, results placed inside $result.
  • The following approach works wherever data is stored in an array
    • /

include("feedcreator.class.php");

$rss = new UniversalFeedCreator(); $rss->useCached(); $rss->title = "Brock University Wiki Server, kumu.brocku.ca"; $rss->description = "List of active Wikis"; $rss->link = "http://kumu.brocku.ca/"; $rss->syndicationURL = "http://kumu.brocku.ca/$_SERVER[PHP_SELF]";

$image = new FeedImage(); $image->title = "Brock University Wiki"; $image->url = "https://kumu.brocku.ca/common/images/defaultBrockWiki_logo.jpg"; $image->link = "http://kumu.brocku.ca/"; $image->description = "Brock University Wiki"; $rss->image = $image;

//create items while ($row = mysql_fetch_assoc($result)) { //You might have an array that your could "foreach" through

$item = new FeedItem(); $item->title = $row['title']; $item->link = 'http://'.$_SERVER['HTTP_HOST'].'/'.$row['namespace']; $item->description = $row['mission']; $item->date = gmdate("D, d M Y H:i:s").' GMT'; //Sat, 07 Sep 2002 09:42:31 GMT $item->source = 'http://'.$_SERVER['HTTP_HOST'].'/'.$row['namespace']; $item->author = $row['title'];

$rss->addItem($item);

}

$rss->saveFeed("RSS1.0", "feed.xml",600); ?>

</source>

[edit] FeedCreator class

Copy n' Paste source: http://ctlet.brocku.ca/rss/feedcreator.class.phps

Originally (c) Kai Blankenhorn http://www.bitfolge.de , http://www.bitfolge.de/rsscreator-en.html

v1.3 work by Scott Reynen and Kai Blankenhorn v1.5 OPML support by Dirk Clemens

Personal tools
Bookmark and Share