Reputation: 11
In my webpage everything works except the rss feed. All the html code and scripts are loaded. But the rss feed is blank. I tried different formats but none is working. Please help. I used the code in seperate file as functions.php and called it in index.php
functions.php
<?php
function parserSide($feedURL) {
$rss = simplexml_load_file($feedURL);
echo "<ul class='newsSide'>";
$i = 0;
foreach ($rss->channel->item as $feedItem) {
$i++;
echo "<li><a href='$feedItem->link' title='$feedItem->title'>" . $feedItem->title . "</a></li>";
if($i >= 5) break;
}
echo "</ul>";
}
index.php
<?php
require_once('functions.php');
parserSide("http://feeds.reuters.com/reuters/technologyNews"); ?>
Upvotes: 1
Views: 835
Reputation: 123
Can't see any problems, except that you're not checking the return value of simplexml_load_file
. On failure, the function will return FALSE
and most likely that is the case. Or, remote file access is disabled for your server as in here: simplexml_load_file not working?
Upvotes: 1
Reputation: 10717
return
instead of echo
in functionfunctions.php
file includedfunction parserSide($feedURL) {
$rss = simplexml_load_file($feedURL);
$output = "<ul class='newsSide'>";
$i = 0;
foreach ($rss->channel->item as $feedItem) {
$i++;
$output .= "<li><a href='$feedItem->link' title='$feedItem->title'>" . $feedItem->title . "</a></li>";
if($i >= 5) break;
}
$output .= "</ul>";
return $output;
}
require_once('functions.php');
echo parserSide("http://feeds.reuters.com/reuters/technologyNews");
Upvotes: 0