Created
          June 22, 2021 12:19 
        
      - 
      
- 
        Save annelyse/3f2dd16ecb2b4eea220ac09551297aac to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?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; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment