2010-10-25 78 views
1

我正在使用SimpleXML解析YouTube搜索Feed。我想在搜索一个术语后在Feed中获得第一个结果。现在我的代码如下所示:尝试解析YouTube搜索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”的价值?

谢谢。

回答

1

另一种方式来访问属性:

echo $xml->entry[0]->link["href"]; 
+0

尼斯。谢谢。 – Psyche 2010-10-25 20:50:17