Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
php get youtube video id from youtube video url
* getYoutubeId
* @par string $video_url
public function getYoutubeId( $url )
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