If anyone is targeting yahoo rss feed may benefit from this snippet
<?php
$rssUrl="http://news.yahoo.com/rss/topstories";
//====================================================
$xml=simplexml_load_file($rssUrl) or die("Error: Cannot create object");
//====================================================
$featureRss = array_slice(json_decode(json_encode((array) $xml ), true ), 0 );
/*Just to see what is in it
use this function PrettyPrintArray()
instead of var_dump($featureRss);*/
function PrettyPrintArray($rssData, $level) {
foreach($rssData as $key => $Items) {
for($i = 0; $i < $level; $i++)
echo(" ");
/*if content more than one*/
if(!is_array($Items)){
//$Items=htmlentities($Items);
$Items=htmlspecialchars($Items);
echo("Item " .$key . " => " . $Items . "<br/><br/>");
}
else
{
echo($key . " => <br/><br/>");
PrettyPrintArray($Items, $level+1);
}
}
}
PrettyPrintArray($featureRss, 0);
?>
You may want to run it in your browser first to see what is there and before looping and style it up pretty simple
To grab the first item description
<?php
echo($featureRss['channel']['item'][0]['description']);
?>
You can see a demo here