Get title from YouTube videos

前端 未结 17 1945
抹茶落季
抹茶落季 2020-12-07 17:30

I want to extract the Title of YouTube\'s videos. How can I do this?

Thanks.

17条回答
  •  粉色の甜心
    2020-12-07 17:45

    // This is the youtube video URL: http://www.youtube.com/watch?v=nOHHta68DdU
    $code = "nOHHta68DdU";
    // Get video feed info (xml) from youtube, but only the title | http://php.net/manual/en/function.file-get-contents.php
    $video_feed = file_get_contents("http://gdata.youtube.com/feeds/api/videos?v=2&q=".$code."&max-results=1&fields=entry(title)&prettyprint=true");
    // xml to object | http://php.net/manual/en/function.simplexml-load-string.php
    $video_obj = simplexml_load_string($video_feed);
    // Get the title string to a variable
    $video_str = $video_obj->entry->title;
    // Output
    echo $video_str;
    

提交回复
热议问题