Created
May 9, 2014 18:56
-
-
Save davist11/2b3488fe9587be959a46 to your computer and use it in GitHub Desktop.
Generate video embed URL from YouTube or Vimeo
This file contains 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 | |
public function getEmbedCode($url) | |
{ | |
if (strpos($url, 'youtube') !== FALSE) { | |
$url_parts = parse_url($url); | |
parse_str($url_parts['query'], $segments); | |
return '//www.youtube.com/embed/' . $segments['v']; | |
} else if (strpos($url, 'vimeo') !== FALSE) { | |
$url_parts = parse_url($url); | |
$segments = explode('/', $url_parts['path']); | |
return '//player.vimeo.com/video/' . $segments[1]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment