dtbi27903 2015-04-15 19:11
浏览 116
已采纳

如何使用PHP - YouTube API从XML文件中检索内容

Please help in using PHP and XML in retrieving dynamic content.

I have this code:

function yt_name() {
$xmlData = file_get_contents( 'http://gdata.youtube.com/feeds/api/users/youtube/uploads?max-results=5&prettyprint=true' ); 
$xml = new SimpleXMLElement($xmlData); 
$yt_name = $xml->event->name;

    echo $yt_name;

}

How can I retrieve the content inside <name>content</name> ?

Regards,

Thank you!

  • 写回答

3条回答 默认 最新

  • doormen2014 2015-04-15 19:31
    关注

    Once inside the object, you can retrieve childs by object index (node name):

    function yt_name() {
        $xmlData = file_get_contents( 'http://gdata.youtube.com/feeds/api/users/youtube/uploads?max-results=5&prettyprint=true' ); 
        $xml = new SimpleXMLElement($xmlData); 
        return $xml;
    }
    
    $yt = yt_name();
    echo $yt->author->name;
    

    Output: YouTube Spotlight

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?