Skip to content

Instantly share code, notes, and snippets.

@tarecord
Last active October 7, 2023 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tarecord/dd9732f69bf5ef6080be2e2ecdac0a23 to your computer and use it in GitHub Desktop.
Save tarecord/dd9732f69bf5ef6080be2e2ecdac0a23 to your computer and use it in GitHub Desktop.
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