Buyrun kullandığım yapıyı veriyim size;
<?php
function validate_youtube_url($url) {
$oEmbed_end_point = "https://www.youtube.com/oembed?url=%s";
$response = (object) array(
"body" => file_get_contents(sprintf($oEmbed_end_point, $url)),
"headers" => get_headers(sprintf($oEmbed_end_point, $url))
);
if(strstr(implode("\n", $response->headers), "200 OK") === false)
return false;
$response->body = json_decode($response->body, true);
if(array_key_exists($response->body, "title") === false)
return false;
$response->body = json_decode(json_encode($response->body));
$thumbnail_url = (object) parse_url($response->body->thumbnail_url);
$thumbnail_url_path = explode("/", trim($thumbnail_url->path, "/"));
return $thumbnail_url_path[1];
}
var_dump(validate_youtube_url("https://www.youtube.com/watch?v=Wg0EXjAX8zc"));