New to PHP and was just playing around with RSS feeds.
I'm currently just trying to display the RSS feed from here: http://www.polygon.com/rss/index.xml
.
Bbut I think my code is broken somewhere and was hoping someone could shed some light on the issue.
This is the function I am using:
<?php
function fetch_news(){
$data = file_get_contents('http://www.polygon.com/rss/index.xml');
$data = simplexml_load_string($data);
$articles = array();
foreach ($data->channel->item as $item){
$articles[] = array(
'title' => (string)$item->title,
'content' => (string)$item->content,
'href' => (string)$item->href,
'published' => (string)$item->published,
);
}
print_r($articles);
}
?>
When loading the page no content is displaying :( All I get is this:
Array ( )
Any Ideas on what I am doing wrong? I'm guessing it has something to do with that foreach statement.
Thanks for any help :)