Easy way to get Vimeo id from a vimeo url
I think using parse_url()
is the best option:
$vimeo = 'https://vimeo.com/29474908';
echo (int) substr(parse_url($vimeo, PHP_URL_PATH), 1);
There are lot many vimeo URLs that are valid. Few examples are
All valid URLs:
http://vimeo.com/6701902
http://vimeo.com/670190233
http://player.vimeo.com/video/67019023
http://player.vimeo.com/video/6701902
http://player.vimeo.com/video/67019022?title=0&byline=0&portrait=0
http://player.vimeo.com/video/6719022?title=0&byline=0&portrait=0
http://vimeo.com/channels/vimeogirls/6701902
http://vimeo.com/channels/vimeogirls/67019023
http://vimeo.com/channels/staffpicks/67019026
http://vimeo.com/15414122
http://vimeo.com/channels/vimeogirls/66882931
All invalid URLs:
http://vimeo.com/videoschool
http://vimeo.com/videoschool/archive/behind_the_scenes
http://vimeo.com/forums/screening_room
http://vimeo.com/forums/screening_room/topic:42708
I wrote this java regex that catches all the above valid URLs and rejects the invalid ones. I m not sure though if they vimeo has more valid URLs.
(https?://)?(www.)?(player.)?vimeo.com/([a-z]*/)*([0-9]{6,11})[?]?.*
Hope this helps...