Get YouTube video title in PHP

后端 未结 7 1696
陌清茗
陌清茗 2021-01-22 22:44

In one of my applications I am saving a YouTube video\'s id... Like "A4fR3sDprOE". I have to display its title in the application. I got the following code for getting

相关标签:
7条回答
  • 2021-01-22 23:12

    It may work to use the error control operators before file_get_contents.

    Something like:

    if($content = @file_get_contents("http://youtube.com/get_video_info?video_id=" . $video_id))
    

    It should remove the error and use it to return false in your if statement.

    Else you can just use try/catch statement (see Exceptions):

    try{
        // Code
    }
    catch (Exception $e){
        // Else code
    }
    
    0 讨论(0)
提交回复
热议问题