Monday, 1 February 2016

YouTube HTML 5 Embed iframe code from URL with PHP

Hi folks
I was making a website and my client request me to upload youtube video on his website. For do this take some fact about youtube video

  • When upload video. Youtube provide a unique URL for every uploaded video which user can use to share their video to other platform or other youtube user.
  • Iframe is used to show youtube video on other website
  • An embedded URL need in iframe SRC
Copy paste following complete code on your website as your requirement.

$url = $_POST['url'];
 preg_match('/[\\?\\&]v=([^\\?\\&]+)/', $url, $matches);
 $id = $matches[1];
 $width = '400px';
 $height = '250px';
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Girfa : Youtube embed video demo</title>


<form method="post"  action=<?php echo "$_SERVER[PHP_SELF]" ?>  >
        Enter youtube video URL : <input type="text" name="url" />
            <input type="submit" value="upload"  name="n" />
        <br /><br />
<iframe id="ytplayer" type="text/html" width="<?php echo $width ?>" height="<?php echo $height ?>"
    src="<?php echo $id ?>?rel=0&showinfo=0&color=white&iv_load_policy=3"
    frameborder="0" allowfullscreen style="border:solid 2px #666666;padding:5px;border-radius:5px;box-shadow: 5px 5px 5px #000"></iframe> 

No comments:

Post a comment