RSS Feed
RSS Feed with PHP and lastRSS
RSS Feed with PHP and lastRSS
Create a RSS Feed with PHP and last RSS, a simple powerful PHP class to parse RSS. Just follow the few easy steps below.
Step 1:
Download lastRSS from here!
Step 2:
Copy and paste the code below in your site, where you want the RSS Feed to appear. Use for the site the file extension *.php instead of *.html, e.g. index.html.
<?php
/*
======================================================================
lastRSS usage DEMO
======================================================================
*/
// include lastRSS
include "./lastRSS.php";
// Create lastRSS object
$rss = new lastRSS;
// Set cache dir and cache time limit (1200 seconds)
// (don't forget to chmod cache dir to 777 to allow writing)
$rss->cache_dir = './temp';
$rss->cache_time = 1200;
// Limit number of returned items. 0 (zero) means "no limit"
$rss->items_limit = 5;
// Try to load and parse RSS file of The Open Designs Community
if ($rs = $rss->get('http://www.openDesigns.org/Design-feed/')) {
// Show clickable website title
echo "<h4><a href=\"$rs[link]\">$rs[title]</a></h4>\n";
// Show last published articles (title, link, description)
echo "";
foreach($rs['items'] as $item) {
echo "\t<p><a href=\"$item[link]\">".$item['title']."</a><br />".$item['description']."</p>\n";
}
echo "</ul>\n";
}
else {
echo "Error: It's not possible to reach RSS file...\n";
}
?>
/*
======================================================================
lastRSS usage DEMO
======================================================================
*/
// include lastRSS
include "./lastRSS.php";
// Create lastRSS object
$rss = new lastRSS;
// Set cache dir and cache time limit (1200 seconds)
// (don't forget to chmod cache dir to 777 to allow writing)
$rss->cache_dir = './temp';
$rss->cache_time = 1200;
// Limit number of returned items. 0 (zero) means "no limit"
$rss->items_limit = 5;
// Try to load and parse RSS file of The Open Designs Community
if ($rs = $rss->get('http://www.openDesigns.org/Design-feed/')) {
// Show clickable website title
echo "<h4><a href=\"$rs[link]\">$rs[title]</a></h4>\n";
// Show last published articles (title, link, description)
echo "";
foreach($rs['items'] as $item) {
echo "\t<p><a href=\"$item[link]\">".$item['title']."</a><br />".$item['description']."</p>\n";
}
echo "</ul>\n";
}
else {
echo "Error: It's not possible to reach RSS file...\n";
}
?>
Step 3:
Change the following lines to your need:
$rss->items_limit = 5; (number of returned items)
if ($rs = $rss->get('http://www.openDesigns.org/Design-feed/')) (URL of RSS Feed).
Step 4:
Upload the files to your server, create a folder named cache and CHMOD it to 777 and you're done!