Created
July 16, 2017 07:45
-
-
Save Debashis-Sinha/b150ee7297a1bb5273d2216c31768dbc to your computer and use it in GitHub Desktop.
php get youtube video id from youtube video url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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