Decode the youtube url link and use it to embed in HTML


<?php
    //REPLACE "youtube_link" WITH THE ACTUAL YOUTUBE LINK like so
    //"http://www.youtube.com/watch?v=H-ZY-qDpPCE"
    $url = "youtube_link";
    if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match)) {
        $video_id = $match[1];
    }
    //NOW $video_id VARIABLE WITH HAVE JUST 'H-ZY-qDpPCE';
?>

<?php
    //JUST ECHO THE $video_id here.
?>
<iframe src="http://www.youtube.com/embed/<?php echo $video_id; ?>" frameborder="0" allowfullscreen></iframe>

Latest Comments

Leave a Reply

comment on this article