November 2006
Intermediate to advanced
46 pages
1h 7m
English
There are a myriad of ways to build an RSS feed with a scripting/programming language. While we can't teach you how to become a proficient programmer, we can provide sample code in a couple of languages to help you get started.
PHP is a very common scripting language used in web site development. This sample PHP script demonstrates one approach to generating an RSS feed:
<?php
// Declare variables
$channelTitle='Seize Her Salad';
$channelDescription='Yummy recipes and tasty tips from Seize Her Salad';
$channelLink='http://seizehersalad.com';
$channelPubDate='Sun, 05 Nov 2006 00:00:01 −0600';
$itemTitle='Fresh Food Tip';
$itemLink='http://seizehersalad.com/recipe?item=234';
$itemDescription="Today's fresh food tip from Seize Her Salad: Want an easy way to
lose weight? Cut out white flour & white sugar from your diet. This is also an
excellent way to reduce your risk of adult-onset diabetes!";
$itemPubDate='Sun, 05 Nov 2006 00:00:01 −0600';
// Build RSS
$rss = <<<EOD
<rss version="1.0">
<channel>
<title>{$channelTitle}</title>
<description>{$channelDescription}</description>
<link>{$channelLink}</link>
<pubDate>{$channelPubDate}</pubDate>
<item>
<title>{$itemTitle}</title>
<link>{$itemLink}</link>
<description>{$itemDescription}</description>
<pubDate>{$itemPubDate}</pubDate>
</item>
</channel>
</rss>
EOD;
// Display RSS
header('Content-type: text/xml');
echo "<?xml version='1.0' encoding='UTF-8'?>\n";
echo $rss;
?>The above script has "hard-coded" variables ...
Read now
Unlock full access