Skip to content

Instantly share code, notes, and snippets.

@iammilton82
Forked from davist11/gist:2b3488fe9587be959a46
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iammilton82/658d80544f68ef538ac0 to your computer and use it in GitHub Desktop.
Save iammilton82/658d80544f68ef538ac0 to your computer and use it in GitHub Desktop.
YouTube Embed
<?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