Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot read yahoo xml feed in php

Tags:

php

xml

yahoo

i am trying to read the yahoo rss (http://news.yahoo.com/rss/us) in php using the xml function

this is myvery simple code:

 $xml = simplexml_load_file('xml.xml');
 var_dump($xml['channel']);

but i shows NULL:

adam@cka: php test.php
NULL

is my XML broken? or there's a better function in php to read xml file?

i can see the elment exists in the XML file and i downloaded the file correctly in my computer.

like image 566
Adam Avatar asked Dec 05 '11 00:12

Adam


1 Answers

SimpleXML returns an object, not an array. Try this:

<?php
 $xml = simplexml_load_file('http://news.yahoo.com/rss/us');
 var_dump($xml->channel);
?>
like image 134
Tak Avatar answered Sep 30 '22 06:09

Tak