Reputation: 6217
I'm trying to use SimpleXML to read our News RSS feed but it's not outputting anything.
Here's my code:
<?php
$rss = simplexml_load_file('http://news.stanford.edu/rss/index.xml');
?>
<h1><?php echo $rss->title; ?></h1>
<ul>
<?php
foreach($rss->item as $e) {
echo "<li><a href=\"".$e->link['href']."\">";
echo $e->title;
echo "</a></li>\n";
}
?>
Upvotes: 1
Views: 2615
Reputation: 14302
Basically, the problem is that in the XML, everything is inside a channel tag. Also, your link doesn't want the ['href'] bit.
<?php
$rss = simplexml_load_file('http://news.stanford.edu/rss/index.xml');
?>
<h1><?php echo $rss->channel->title; ?></h1>
<ul>
<?php
foreach($rss->channel->item as $chan) {
echo "<li><a href=\"".$chan->link."\">";
echo $chan->title;
echo "</a></li>\n";
}
?>
Here is a link to the documentation for that function
Upvotes: 2