How can PHP be used to check the availability of a YouTube video?

To check the availability of a YouTube video using PHP, you can make a request to the YouTube Data API to retrieve information about the video. You can then check the response to see if the video exists or if there are any errors.

<?php

$videoId = "YOUR_VIDEO_ID";
$apiKey = "YOUR_API_KEY";

$url = "https://www.googleapis.com/youtube/v3/videos?id=" . $videoId . "&key=" . $apiKey . "&part=snippet";

$response = file_get_contents($url);
$data = json_decode($response, true);

if(isset($data['items'][0])){
    echo "Video is available.";
} else {
    echo "Video is not available or does not exist.";
}

?>