Search code examples
phpxmlyahoo

cannot read yahoo xml feed in php


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.


Solution

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

    <?php
     $xml = simplexml_load_file('http://news.yahoo.com/rss/us');
     var_dump($xml->channel);
    ?>