You are here

function royalsliderfield_get_video_id in RoyalSlider Integration 7

Get YouTube or vimeo video ID.

Parameters

string $url: Accepts video URLs in following formats:

  • youtube.com/watch?v=VIDEO_ID
  • youtu.be/VIDEO_ID
  • vimeo.com/VIDEO_ID

Return value

string Video ID or FALSE.

1 call to royalsliderfield_get_video_id()
royalsliderfield_preprocess_royalsliderfield_slide in contrib/royalsliderfield/royalsliderfield.module
Implements hook_preprocess_HOOK().

File

contrib/royalsliderfield/royalsliderfield.module, line 513
RoyalSlider Field module.

Code

function royalsliderfield_get_video_id($url) {
  if (strstr($url, 'youtube.com/watch?') && preg_match('/v=[^&]*(?=&|$)/', $url, $matches)) {
    $video_id = ltrim($matches[0], 'v=');
  }
  elseif (strstr($url, 'youtu.be/')) {
    $anchor = 'be/';
    $position = strpos($url, $anchor);
    $video_id = trim(substr($url, $position + strlen($anchor)));
  }
  elseif (strstr($url, 'vimeo.com/') && preg_match('([0-9]+)', $url, $matches)) {
    $video_id = $matches[0];
  }
  if (!empty($video_id)) {
    return $video_id;
  }
  return FALSE;
}