elin-r
10/4/2016 - 10:23 AM

Hämta RSS med PHP / simpleXML

Hämta RSS med PHP / simpleXML

<?php
$html = "";
$url = "http://www.gp.se/?rss";
$xml = simplexml_load_file($url);
for($i = 0; $i < 10; $i++){
	$title = $xml->channel->item[$i]->title;
	$link = $xml->channel->item[$i]->link;
	$description = $xml->channel->item[$i]->description;
	$pubDate = $xml->channel->item[$i]->pubDate;
	
        $html .= "<a href='$link'><h3>$title</h3></a>";
	$html .= "$description";
	$html .= "<br />$pubDate<hr />";
}
echo $html;
?>