tags:

views:

36

answers:

2

Hello,

I'm using SimpleXML to parse a YouTube search feed. I want to get the first result in the feed after searching for a term. Right now my code looks like this:

set_time_limit(0);

// Include needed files
require_once "config.php";

$xml = simplexml_load_file('http://gdata.youtube.com/feeds/base/videos?q=V.I.P.+KE%24HA&client=ytapi-youtube-search&v=2');

print_r($xml->entry[0]->link);

The output for the code above is:

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [rel] => alternate
            [type] => text/html
            [href] => http://www.youtube.com/watch?v=TveGAmLdn8k&feature=youtube_gdata
        )

)

How can i get the value of "href" ?

Thank you.

+1  A: 

Check out the attributes method to a SimpleXML Object

gms8994
+1  A: 

Another way to access the attributes:

echo $xml->entry[0]->link["href"];
Repox
Nice. Thank you.
Psyche