Answers for "laravel if valid youtube link url"

PHP
0

laravel if valid youtube link url

$url = "www.youtube.com/cCnrX1w5luM";

$regex_pattern = "/(youtube.com|youtu.be)\/(watch)?(\?v=)?(\S+)?/";

$match;

if (
  	filter_var($url, FILTER_VALIDATE_URL) 
  	&& preg_match($regex_pattern, $url, $match)
 ) {
    echo "Youtube video id is: ".$match[4];
} else {
    echo "Sorry, not a youtube URL";
}
Posted by: Guest on April-15-2021

Browse Popular Code Answers by Language