Urdu English
English English Deutsch Deutsch Español Español Français Français Italiano Italiano Nederlands Nederlands Português Português Русский Русский Ελληνικά Ελληνικά

Welcome to Jumi! >> Tutorial >> RSS Feeds Grabber

Basic script to grab the results from a RSS feed. Results are cahced for two hours (by default) so no bandwidth issues!


You need to create new Jumi application with the following code below.

You can add the /* config */ part of the script to Custom Script field, for making changes easily from the Joomla! admin interface. Otherwise you need to edit the rss_grabber.php file every time you need to make changes.

<?php defined("_JEXEC") or die("Restricted access"); ?>
/* config */
$rss_url    = "http://edo.webmaster.am/rss";
$file_name  = 'cache/'.md5($rss_url);
$cache_time = 2*60*60; // 2 hours

// check cache
if(file_exists($file_name) and strtotime('now') - filemtime($file_name) < $cache_time) {
    $rss = file_get_contents($file_name);
} else {
    // retrieve feed from server
    $rss = file_get_contents($rss_url);
    // cache content
    if(strlen($rss) > 3000)
        file_put_contents($file_name, $rss);

$rss = simplexml_load_string($rss);

echo '<h1 style="border-bottom:2px solid threedlightshadow;font-size:160%;margin:0 0 0.2em;">', $rss->channel->title, '</h1>', "\n";
echo '<h2 style="color:threeddarkshadow;font-size:110%;font-weight:normal;margin:0 0 0.6em;">', $rss->channel->description, '</h2>', "\n";

foreach($rss->channel->item as $item) {
    echo '<div class="entry">', "\n";
    echo '<h3><a href="', $item->link, '">', $item->title, '</a><div style="font-size:85%;font-weight:normal;">', $item->pubDate, '</div></h3>', "\n";
    echo '<div base="', $rss_url, '" style="font-size:110%;">', $item->description, '</div>', "\n";
    echo '</div>', "\n";

Your host must support PHP SimpleXML library.

RSS version need to be 2.0