尝试解析YouTube搜索Feed时出错

时间:2010-10-25 20:24:59

标签: php xml youtube

我正在使用SimpleXML来解析YouTube搜索Feed。我希望在搜索一个术语后获得Feed中的第一个结果。现在我的代码看起来像这样:

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);

上面代码的输出是:

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

)

如何获得“href”的值?

谢谢。

2 个答案:

答案 0 :(得分:1)

查看SimpleXML对象的attributes方法

答案 1 :(得分:1)

访问属性的另一种方法:

echo $xml->entry[0]->link["href"];
相关问题