Skip to content

Instantly share code, notes, and snippets.

@Kiyumars
Created April 27, 2014 10:43
Show Gist options
  • Save Kiyumars/11342623 to your computer and use it in GitHub Desktop.
Save Kiyumars/11342623 to your computer and use it in GitHub Desktop.
Youtube looper
<?php
if (isset($_POST['video_req']) && ! empty($_POST['video_req'])){
if ( preg_match("+youtube.com+", $_POST['video_req']) ) {
$video = htmlspecialchars($_POST['video_req']);
$strpos_yt = strpos($video, "youtube.com");
$beginning = substr($video, 0, $strpos_yt) ;
if ($beginning != "http://www." )
{$video = substr_replace ($video, "http://www.", 0, $strpos_yt ) ;}
if (substr_count($video, "watch?v=") >0 )
{$video = str_replace('watch?v=', 'embed/', $video) ;}
$end = strpos($video, "embed/");
$video_id = substr($video, $end + 6);
$video .= "?enablejsapi=1&version=3&autoplay=1&loop=1&playlist="
. $video_id;
echo '<iframe width="560" height="315" src="' . $video .
'" frameborder="0" allowfullscreen></iframe>';
} else
{echo "Please enter a valid youtube url.";}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment