Fatal error: Call to undefined method SimpleXMLElement::attr

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
anjshr7
Forum Newbie
Posts: 19
Joined: Fri Jul 17, 2015 1:28 pm

Fatal error: Call to undefined method SimpleXMLElement::attr

Post by anjshr7 »

Fatal error: Call to undefined method SimpleXMLElement::attribute() in D:\Program Files\wamp\www\New folder\ndtv_news.php on line 13

How to define method .....

<?php
//fetches articles from NDTV news RSS feed
function 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;
}

?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Fatal error: Call to undefined method SimpleXMLElement::

Post by requinix »

Learn to use the PHP Code tags: paste your code into the textbox, select it, and click the PHP Code button.
anjshr7
Forum Newbie
Posts: 19
Joined: Fri Jul 17, 2015 1:28 pm

Re: Fatal error: Call to undefined method SimpleXMLElement::

Post by anjshr7 »

Can you give me an example.... :wink:
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Fatal error: Call to undefined method SimpleXMLElement::

Post by requinix »

Check your other threads? I know a couple of us moderators have edited them for you. Or follow the three steps I posted.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Fatal error: Call to undefined method SimpleXMLElement::

Post by Celauran »

viewtopic.php?f=1&t=141571

One thread per topic is enough, thank you.
Locked