php const RSS_URL http mysite local news rss xml const FILE_NAME news

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<?php
const RSS_URL = 'http://mysite.local/news/rss.xml';
const FILE_NAME = 'news.xml';
function download($url, $filename){
file_put_contents($filename, file_get_contents($url));
}
if (!file_exists(FILE_NAME) or fileatime(FILE_NAME) + 3600 < time()) {
download(RSS_URL, FILE_NAME);
}
$sxml = simplexml_load_file(FILE_NAME);
for ($i=0; $i < count($sxml->channel[0]->item); $i++) {
echo <<<LABEL
<h2>{$sxml->channel[0]->item[$i]->title}</h2>
<p>{$sxml->channel[0]->item[$i]->description}</p>
LABEL;
}
?>