Skip to content

Instantly share code, notes, and snippets.

@davidsword
Created September 14, 2016 21:53
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 davidsword/1a2ca1590c0908c0989a966f8ef8d02d to your computer and use it in GitHub Desktop.
Save davidsword/1a2ca1590c0908c0989a966f8ef8d02d to your computer and use it in GitHub Desktop.
get-embed-from-youtube-or-vimeo-url-2.php
<?
$vimeo_url = '';//? get the URL from somewhere
preg_match('/^https*?:\/\/(www\.)?vimeo\.com\/(clip\:)?(\d+).*$/', $vimeo_url, $match);
$id = $match[3];
$hash = @unserialize(file_get_contents("http://vimeo.com/api/v2/video/{$id}.php"));
$video = $hash[0];
//find ratio for proper height:
if ($video['width'] > 0) {
$newheight = (($video['height'] * 670) / $video['width']);
echo "<iframe src='http://player.vimeo.com/video/{$id}' width='670' height='{$newheight}'".
" frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>";
} else {
echo "ERROR EMBEDDING - VIDEO MIGHT BE PRIVATE";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment