Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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];
}
@jpibarra1130

This comment has been minimized.

Show comment Hide comment
@jpibarra1130

jpibarra1130 Apr 5, 2014

I think the gist won't work for channels.

e.g. http://vimeo.com/channels/hdmusicvideos/90306625

I tried removing the string videos on line 9 and it worked for me

I think the gist won't work for channels.

e.g. http://vimeo.com/channels/hdmusicvideos/90306625

I tried removing the string videos on line 9 and it worked for me

@wwdboer

This comment has been minimized.

Show comment Hide comment
@mwordpress

This comment has been minimized.

Show comment Hide comment
@mwordpress

mwordpress Nov 13, 2014

nice work

nice work

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