Fetching Dilbert Comic stripts from rss feed

10:17PM Apr 17, 2009 in category PHP by Alexander Pirsig

This is a php script to fetch dilbert images out of a feedburner feed. Its a quick an dirty implementation it works and I'm sure there are bug's in it.

Enjoy! :D ... ah you can find the testside here -> testside or download it here
<\?php
/**
 * Make Sure XML is cached for couple of minutes
 */
$tmpfile = '/tmp/dilbert.rss';
$gap = 60*60*1; # 1 hour(s)

if(file_exists($tmpfile)===true && (filemtime($tmpfile)+$gap)>time())
{
  # Use locale cached dilbert Content
  $xmlStr = file_get_contents($tmpfile);
}
else
{
  # Reload Cached DilbertFeed
  if(!file_exists($tmpfile))
  {
    touch($tmpfile);
  }
  $xmlStr = file_get_contents('http://feeds2.feedburner.com/DilbertDailyStrip?format=rss');
  file_put_contents($tmpfile,$xmlStr);
}
$xml = new simpleXMLElement($xmlStr);
$content = $xml->xpath('//item');
\?>








  • ".$content[0]->title.""; ?> <\?php preg_match($expr,$content[0]->description,$matches); \?> enclosure['url'] = $matches[1]; \?> <\?php echo "".$content[0]->title.""; \?> <\?php echo "
    Fetched: ".date('Y-m-d H:i:s', filemtime($tmpfile)); \?>

Kommentare[0] Tags: php simple xml dilbert xpath coding labs rss