Skip to content

Instantly share code, notes, and snippets.

@prolificjones82
Last active November 9, 2020 12:12
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 prolificjones82/e4d22fddd6fccb29c132 to your computer and use it in GitHub Desktop.
Save prolificjones82/e4d22fddd6fccb29c132 to your computer and use it in GitHub Desktop.
YouTube Video Display
<?php
// get youtube video id
preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $attrs['videoid'], $matches);
$id = $matches[0];
// get video title
$content = file_get_contents('http://youtube.com/get_video_info?video_id='.$id);
parse_str($content, $ytarr);
// variables
$ytAnchor = '//www.youtube.com/embed/'.$id.'?autoplay=1&showinfo=0&modestbranding=1';
$ytIframe = '//www.youtube.com/embed/'.$id.'?showinfo=0&modestbranding=1';
$ytThumb = '//img.youtube.com/vi/'.$id.'/maxresdefault.jpg';
$ytTitle = $ytarr['title'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment