A simple way to parse an RSS feed with SimpleXML.
<?php
$cache_time = 3600*24; // 24 hours
$cache_file = $_SERVER['DOCUMENT_ROOT'].'/cache/feed.rss';
$timedif = @(time() - filemtime($cache_file));
if (file_exists($cache_file) && $timedif < $cache_time) {
$string = file_get_contents($cache_file);
} else {
$string = file_get_contents('http://www.scriptgeni.com/feed/');
if ($f = @fopen($cache_file, 'w')) {
fwrite ($f, $string, strlen($string));
fclose($f);
}
}
$xml = simplexml_load_string($string);
// place the code below somewhere in your html
echo '
<div>
<ul>';
$count = 0;
$max = 3;
// Present each rss item
foreach ($xml->channel->item as $val) {
if ($count < $max) {
echo '
<li>
<strong>'.$val->title.'</strong><br />
'.$val->description.' | <a href="'.$val->link.'">More ></a>
</li>';
}
$count++;
}
echo '
</ul>
</div>';
?>