Created
February 5, 2014 20:07
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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