Skip to content

Instantly share code, notes, and snippets.

@anjan011
Created November 11, 2015 14:39
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save anjan011/1fcecdc236594e6d700f to your computer and use it in GitHub Desktop.
Save anjan011/1fcecdc236594e6d700f to your computer and use it in GitHub Desktop.
php - get vimeo video id from url
<?php
/**
* Get Vimeo video id from url
*
* Supported url formats -
*
* https://vimeo.com/11111111
* http://vimeo.com/11111111
* https://www.vimeo.com/11111111
* http://www.vimeo.com/11111111
* https://vimeo.com/channels/11111111
* http://vimeo.com/channels/11111111
* https://vimeo.com/groups/name/videos/11111111
* http://vimeo.com/groups/name/videos/11111111
* https://vimeo.com/album/2222222/video/11111111
* http://vimeo.com/album/2222222/video/11111111
* https://vimeo.com/11111111?param=test
* http://vimeo.com/11111111?param=test
*
* @param string $url The URL
*
* @return string the video id extracted from url
*/
function getVimeoVideoIdFromUrl($url = '') {
$regs = array();
$id = '';
if (preg_match('%^https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)(?:[?]?.*)$%im', $url, $regs)) {
$id = $regs[3];
}
return $id;
}
@luisrock
Copy link

Nice! thanks.

@sunnysideup
Copy link

Nice THANKS!

@bdkoder
Copy link

bdkoder commented Jul 4, 2020

Nice!
But not support everything of the Vimeo link.
This link not working: https://vimeo.com/277465256#t=60s

@cavaon-wayne
Copy link

You can use this reg to achieve:
%^https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\#?)(?:[?]?.*)$%im

Nice!
But not support everything of the Vimeo link.
This link not working: https://vimeo.com/277465256#t=60s

@poonga
Copy link

poonga commented Mar 20, 2021

Hi
I have a different Vimeo URL (https://vimeo.com/355415017/1b3271f41f). What is the id of this URL?

@usamarauf93
Copy link

how to get video details from id?

@benjaminhull
Copy link

how to get video details from id?

You can only do that with their API: https://developer.vimeo.com/api/reference/videos#get_video

Pretty straight forward though.

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