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
anjshr7
Forum Newbie
Posts: 19 Joined: Fri Jul 17, 2015 1:28 pm
Post
by anjshr7 » Mon Jul 20, 2015 7:43 am
Parse error: syntax error, unexpected '$item' (T_VARIABLE), expecting ')' in D:\Program Files\wamp\www\New folder\ndtv_news.php on line 18
ndtv_news.php
Code: Select all
<?php
//fetches articles from NDTV news
function fetch_news(){
$data = file_get_contents('http://feeds.bcci.co.uk/news/rss.xml');
$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' => (srting)$item->title,
'description' => (srting)$item->description,
'link' => (srting)$item->link,
'date' => (srting)$item->pubDate,
'image' => $image);
}
return $articles;
}
?>
Last edited by
Celauran on Mon Jul 20, 2015 7:44 am, edited 1 time in total.
Reason: Please wrap your code in syntax tags
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Mon Jul 20, 2015 7:45 am
You have a typo where you're trying to cast to 'srting' rather than 'string'
anjshr7
Forum Newbie
Posts: 19 Joined: Fri Jul 17, 2015 1:28 pm
Post
by anjshr7 » Mon Jul 20, 2015 7:53 am
Now i am getting ..
Warning: simplexml_load_string(): Entity: line 34: parser error : EntityRef: expecting ';' in D:\Program Files\wamp\www\New folder\ndtv_news.php on line 6
Trying to get property of non-object in D:\Program Files\wamp\www\New folder\ndtv_news.php on line 9
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Mon Jul 20, 2015 8:17 am
Have you checked what you're getting back from file_get_contents? That URL does not appear to be valid.
anjshr7
Forum Newbie
Posts: 19 Joined: Fri Jul 17, 2015 1:28 pm
Post
by anjshr7 » Mon Jul 20, 2015 8:21 am
ohh... now i checked its working but showing differt error...
Fatal error: Call to undefined method SimpleXMLElement::attribute() in D:\Program Files\wamp\www\New folder\ndtv_news.php on line 12
anjshr7
Forum Newbie
Posts: 19 Joined: Fri Jul 17, 2015 1:28 pm
Post
by anjshr7 » Mon Jul 20, 2015 1:56 pm
Can u please tell me in the code how to do because its 1st tym i am using xml.....
Pazuzu156
Forum Contributor
Posts: 241 Joined: Sat Nov 20, 2010 9:00 pm
Location: GA, USA
Contact:
Post
by Pazuzu156 » Fri Jul 24, 2015 5:41 pm
anjshr7 wrote: Can u please tell me in the code how to do because its 1st tym i am using xml.....
I replied to another post you made, personally I wouldn't make duplicate posts for the same problem.
Refer to the comment I posted there for an example using code:
viewtopic.php?f=1&t=141570&p=700729#p700729