Skip to content

Instantly share code, notes, and snippets.

@tarecord

tarecord/get_vimeo_id.php

Last active Feb 18, 2020
Embed
What would you like to do?
A function that takes a vimeo url and returns the video ID
<?php
function get_vimeo_id( $url ) {
/**
* Matches:
* https://player.vimeo.com/video/123456789
* https://vimeo.com/123456789
* https://www.vimeo.com/123456789
*/
preg_match( '/(vimeo\.com\/)(?:video\/)?([\d]+)/', $url, $matches );
$vimeo_id = $matches[2];
return $vimeo_id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment