-
-
Save iammilton82/658d80544f68ef538ac0 to your computer and use it in GitHub Desktop.
YouTube Embed
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