Skip to content

Instantly share code, notes, and snippets.

@silasrm
Forked from wwdboer/gist:4943672
Last active May 8, 2019 17:20
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 silasrm/01fa03f78e0f8646ecbc0fed1f337e56 to your computer and use it in GitHub Desktop.
Save silasrm/01fa03f78e0f8646ecbc0fed1f337e56 to your computer and use it in GitHub Desktop.
PHP: Get Vimeo ID
function get_vimeoid( $url ) {
$regex = '~
# Match Vimeo link and embed code
(?:<iframe [^>]*src=")? # If iframe match up to first quote of src
(?: # Group vimeo url
https?:\/\/ # Either http or https
(?:[\w]+\.)* # Optional subdomains
vimeo\.com # Match vimeo.com
(?:[\/\w:]*(?:\/videos)?)? # Optional video sub directory this handles groups links also
\/ # Slash before Id
([0-9]+) # $1: VIDEO_ID is numeric
[^\s]* # Not a space
) # End group
"? # Match end quote if part of src
(?:[^>]*></iframe>)? # Match the end of the iframe
(?:<p>.*</p>)? # Match any title information stuff
~ix';
preg_match( $regex, $url, $matches );
return $matches[1];
}
@silasrm
Copy link
Author

silasrm commented May 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment