Skip to content

Instantly share code, notes, and snippets.

@joeydsmith
Created September 24, 2015 17:21
Show Gist options
  • Save joeydsmith/0dca54dd957395781e29 to your computer and use it in GitHub Desktop.
Save joeydsmith/0dca54dd957395781e29 to your computer and use it in GitHub Desktop.
// Video Related Functions
function parseVideoUrl($search){
//setup matcher
$matcher = '([a-zA-Z0-9-_]+)';
//setup the patterns
$patterns = array(
'youtube\.com\/watch\?v\='.$matcher => 'youtube',
'youtu\.be\/'.$matcher => 'youtube',
'youtube\.com\/embed\/'.$matcher => 'youtube',
'youtube\.com\/v\/'.$matcher => 'youtube',
'facebook.com\/photo\.php\?v\='.$matcher => 'facebook'
);
foreach($patterns as $pattern => $type){
if(preg_match('/'.$pattern.'/',$search,$matches)){
return array('id' => $matches[1], 'type' => $type);
}
}
return array('data' => $search, 'type' => 'none');
}
// Video Related Functions
function getVideoOutput($array,$width='100%',$height='315'){
switch($array['type']){
case 'youtube':
return '<div class="embed"><iframe class="videoframe" src="https://www.youtube.com/embed/'.$array['id'].'" width="'.$width.'" height="'.$height.'" frameborder="0" allowfullscreen></iframe></div>';
}
return $array['data'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment