Hey,
Having some troubles extracting data from simpleXML object.
var_dump outputs all the stuff correctly but when i try access data in the object, it just comes back empty.
$rss = "/data/rss/";
$rss = file_get_contents($rss); // simplexml_load_file() fails
$feed = new SimpleXMLElement($rss);
foreach($feed->item as $news) {
echo $news->title; // returns empty
}
echo $feed->item->title; // also is empty
so var_dump($feed) outputs this, shortened version:
object(SimpleXMLElement)#10 (2) { ["@attributes"]=> array(1) { ["version"]=> string(3) "2.0" } ["channel"]=> object(SimpleXMLElement)#11 (6) { ["title"]=> string(38) "Bradford Bulls Super League Rugby News" ["description"]=> string(75) "RSS Feed for the latest Bradford Bulls Super League rugby news and updates." ["link"]=> string(46) "http://www.superleaguefans.com/bradford-bulls/" ["language"]=> string(2) "en" ["pubDate"]=> string(26) "Sat, 03 Sep 13:42:39 +0100" ["item"]=> array(10){ [0]=> object(SimpleXMLElement)#12 (1) { ["title"]=> string(32) "Briggs and Walker in Bulls squad" } } } }
so, $feed->item->title should return the ["title"] contents, but it doesn't, driving me crazy.
what am i doing wrong? Any pointers will be much appreciated, thank you.