Skip to content

Instantly share code, notes, and snippets.

@Debashis-Sinha
Created July 16, 2017 07:45
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 Debashis-Sinha/b150ee7297a1bb5273d2216c31768dbc to your computer and use it in GitHub Desktop.
Save Debashis-Sinha/b150ee7297a1bb5273d2216c31768dbc to your computer and use it in GitHub Desktop.
php get youtube video id from youtube video url
/**
* getYoutubeId
* @par string $video_url
*/
public function getYoutubeId( $url )
{
// http://stackoverflow.com/a/10315969/2252921
preg_match('/^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/', $url, $founded);
return !empty( $founded ) ? $founded[1] : '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment