Skip to content

Instantly share code, notes, and snippets.

@AndrewChamp
Created February 5, 2014 20:07
Show Gist options
  • Save AndrewChamp/8831977 to your computer and use it in GitHub Desktop.
Save AndrewChamp/8831977 to your computer and use it in GitHub Desktop.
Downloads and caches content from Google's News RSS feed. This example is for sports.
<?php
$sports = 'https://news.google.com/news/feeds?ned=us&topic=s&output=rss';
$feedCache = 'feed.xml';
if(!file_exists($feedCache)):
fopen($feedCache, 'w');
$saveSports = file_get_contents($sports);
$saveSports = file_put_contents($feedCache, $saveSports);
elseif((time() - filemtime($feedCache)) > 3600):
$saveSports = file_get_contents($sports);
$saveSports = file_put_contents($feedCache, $saveSports);
endif;
$xml = simplexml_load_file($feedCache);
foreach($xml->channel->item as $item):
print '<li><a href="'.$item->link.'" target="_blank">'.$item->title.'</a></li>';
endforeach;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment