0
votes

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(' & ', ' &amp; ', $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.

1
If you go to this URL blog.techbreeze.in/feed you will see your feed is redirecting to feedburner. Which is why you can't pull in the feed from that URL.topdown
I had to redirect it to feedburner to solve the DOM error, ever since i have redirected it to feedburner and used their url the thing started working just fine. The problem is solved but i still wonder why the error was causedRick Roy

1 Answers

0
votes

Instead try with this url: http://feeds.feedburner.com/techbreeze/itvO

The error is because your feed is redirected to the feedburner url.