TEENFRONT Posted September 3, 2011 Share Posted September 3, 2011 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. Link to comment https://forums.phpfreaks.com/topic/246346-simplexml-trouble-with-extracting-data/ Share on other sites More sharing options...
TEENFRONT Posted September 3, 2011 Author Share Posted September 3, 2011 strangely, also an example from the net returns empty aswell. $xml = ' <?xml version="1.0" encoding="ISO-8859-1"?> <cars> <make name="Ford"> <model>Mustang</model> </make> <make name="Honda"> <model>Accord</model> </make> </cars> '; $xml = simplexml_load_string($xml); echo $xml->make[0]['name']; that doesnt work either, just outputs nothing. Link to comment https://forums.phpfreaks.com/topic/246346-simplexml-trouble-with-extracting-data/#findComment-1265062 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.