Skip to content

Instantly share code, notes, and snippets.

@Artisan-Asad
Last active July 24, 2018 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Artisan-Asad/453433ae20ab19c25a2ce382a95cc50d to your computer and use it in GitHub Desktop.
Save Artisan-Asad/453433ae20ab19c25a2ce382a95cc50d to your computer and use it in GitHub Desktop.
Verify youtube link in PHP application
function get_youtube_id( $video_url ){
if( (preg_match('/http:\/\/(www\.)*youtube\.com\/.*/',$video_url)) || (preg_match('/http:\/\/(www\.)*youtu\.be\/.*/',$video_url)) )
{
$video_id = ( preg_match( '%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $video_url, $match ) ) ? $match[1] : false;
return $video_id;
} else
{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment