Skip to content

Instantly share code, notes, and snippets.

@Lotuashvili
Last active March 21, 2017 13:48
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 Lotuashvili/ef6befd00d659c9eda68271ca1d471cb to your computer and use it in GitHub Desktop.
Save Lotuashvili/ef6befd00d659c9eda68271ca1d471cb to your computer and use it in GitHub Desktop.
Filter Youtube link to parse only video ID (for embedding in website)
<?php
funtion parseYoutubeVideoID($link) {
preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $link, $matches);
return $matches[1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment