【问题标题】:Error while trying to parse a YouTube search feed尝试解析 YouTube 搜索提要时出错
【发布时间】:2011-04-30 10:23:53
【问题描述】:

我正在使用 SimpleXML 解析 YouTube 搜索提要。我想在搜索一个词后在提要中获得第一个结果。现在我的代码如下所示:

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”的值?

谢谢。

【问题讨论】:

    标签: php xml youtube


    【解决方案1】:

    查看 SimpleXML 对象的 attributes 方法

    【讨论】:

      【解决方案2】:

      访问属性的另一种方式:

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

      【讨论】:

        猜你喜欢
        • 2022-01-16
        • 2017-09-12
        • 1970-01-01
        • 1970-01-01
        • 2014-01-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多