Log in

View Full Version : RSS Feed Help



moose86
12-20-2013, 11:37 PM
Hi All,

I have a simple RSS feed displayer for my website, but it is not working, I have tried to go through the code ans see what's wrong but I can't seem to find anything, if you could help that would be great :D


<?php
if ($rss = DOMDocument::load('http://companynewssepro.blogspot.com/feeds/posts/default?alt=rss')) {
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$feed[] = 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,
);
}
$limit = 10;
foreach($feed as $index => $feed_item) {
//If the index (current number in array) is greater or equal to your limit stop processing.
if ($index >= $limit)
break;
$feed_item = (object)$feed_item;
$title = htmlentities(strip_tags($feed_item->title));
$link = $feed_item->link;
$description = htmlentities(strip_tags($feed_item->desc));
$date = date('l F d, Y', strtotime($feed_item->date));
echo '<font class="rss-title">'.$title.'</font><br />'; //
echo '<font class="rss-disc">'.$description.'</font><br />'; //
echo '<font class="rss-date">Posted on '.$date.'</font><p>';
}
}
?>

Thanks Guys :D

jscheuer1
12-21-2013, 07:29 AM
Seems to work OK to me. I get:


MERRY CHRISTMAS
Merry Christmas from all here at StormsEdge Productions and may 2014 be a wonderful year for everyone :D
Posted on Tuesday December 17, 2013

jscheuer1
12-21-2013, 08:03 PM
BTW, the code requires PHP 5 or later.

moose86
12-22-2013, 12:16 AM
Sorry John, i'm a bit of a PHP noob (i got this script of the internet somewhere) what do i need to do as u said it requires PHP 5 or later?

Thanks

jscheuer1
12-22-2013, 04:37 AM
There could also be other requirements like permission to open and read files. Look at your phpinfo() to see what version you're running. If you don't already have phpinfo, just make up a file:


<?php
phpinfo();
?>

moose86
12-22-2013, 08:26 PM
Hi John, im runing 5.4.21 on my server

moose86
12-22-2013, 09:47 PM
Hi John, just thought illd let you know that I sorted it out, the error was a setting on my hosts cp