anjshr7 Posted July 21, 2015 Share Posted July 21, 2015 Fatal error: Call to undefined method SimpleXMLElement::attribute() in D:\Program Files\wamp\www\New folder\ndtv_news.php on line 13How to define method .....<?php//fetches articles from NDTV news RSS feedfunction fetch_news(){$data = file_get_contents('http://feeds.feedburner.com/News-TN');$data = simplexml_load_string($data);$articles = array();foreach ($data->channel->item as $item){$media = $item->children('http://search.yahoo.com/mrss');$image = array();foreach($media->attribute() as $key => $value){$image[$key] = (string)$value;}$articles[] = array('title'=>(string)$item->title,'description'=>(string)$item->description,'link'=>(string)$item->link,'date'=>(string)$item->pubDate,'image'=>'$image');}return $articles;}?> Quote Link to comment https://forums.phpfreaks.com/topic/297395-fatal-error-call-to-undefined-method-simplexmlelementattribute/ Share on other sites More sharing options...
requinix Posted July 21, 2015 Share Posted July 21, 2015 Read the documentation. Quote Link to comment https://forums.phpfreaks.com/topic/297395-fatal-error-call-to-undefined-method-simplexmlelementattribute/#findComment-1516907 Share on other sites More sharing options...
anjshr7 Posted July 21, 2015 Author Share Posted July 21, 2015 i had already read this but exactly not getting can u please correct the code ...... Quote Link to comment https://forums.phpfreaks.com/topic/297395-fatal-error-call-to-undefined-method-simplexmlelementattribute/#findComment-1516908 Share on other sites More sharing options...
requinix Posted July 21, 2015 Share Posted July 21, 2015 No. There is no method named "attribute". Look at the documentation more closely. While I'm here, there are other problems with the code: - Either I'm blind or there is no "http://search.yahoo.com/mrss" namespace in the XML. - I doubt $media->attribute() (after it gets fixed) will return what you want because $media is a set of elements. - '$image' will be the literal value "$image". Variables don't work in single-quoted strings. Plus, it's an array so don't put it in a string to begin with. Quote Link to comment https://forums.phpfreaks.com/topic/297395-fatal-error-call-to-undefined-method-simplexmlelementattribute/#findComment-1516993 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.