I am trying to fetch the rss feed from my blog and display the most recent 5 posts into my website, the php code that I am using is shown below
<?php
$rss = new DOMDocument();
$rss->load('http://blog.techbreeze.in/feed/');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
);
array_push($feed, $item);
}
$limit = 5;
for($x=0;$x<$limit;$x++) {
$title = str_replace(' & ', ' & ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$description = $feed[$x]['desc'];
$date = date('l F d, Y', strtotime($feed[$x]['date']));
echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
echo '<small><em>Posted on '.$date.'</em></small></p>';
echo '<p>'.$description.'</p>';
}
?>
The trouble is, the code works just fine when i test it on my local server which is running WAMP, but when I upload it to the production server, which is linux based and running Centos and test it I am getting strange errors which I don't understand why. The errors I am getting are
Warning: DOMDocument::load() [domdocument.load]: Document is empty in http://blog.techbreeze.in/feed/, line: 1 in /home//*/blog.php on line 4
Warning: DOMDocument::load() [domdocument.load]: Start tag expected, '<' not found in http://blog.techbreeze.in/feed/, line: 1 in /home//*/blog.php on line 4
Please help me understand what is wrong and how to solve this.