How do I check if a video exists on YouTube, using PHP?

后端 未结 14 1618
[愿得一人]
[愿得一人] 2020-11-27 06:40

How do I check if a video exists on YouTube, using PHP?

14条回答
  •  春和景丽
    2020-11-27 07:07

    Found this solution on github: Check if youtube video exists

    Easy to use:

    $headers = get_headers('http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=nonexistingid');
    
    if (!strpos($headers[0], '200')) {
        echo "The YouTube video you entered does not exist";
    }
    

    Working fine.

提交回复
热议问题