I want to fetch youtube video id from the URL but YouTube has many different patterns for the URL. I am getting thumbnails from one of the patterns which is (https://www.youtube.com/watch?v=4Wm6-8X3Vq4) but unable to get from this type of URL (https://youtu.be/HCjNJDNzw8Y) and this is my code. And I want this code should work for both of the URLs. Plz, Help!
if (isset($_POST["Submit"])) {
$url = $_POST["url"];
$value = explode('v=', $url);
$videoId = $value[1];
} ?>