CODE CODIFY.CLUB

PHP : Fetch YouTube video id and image path from video url

<form method=”post” action=”” >

    <div class=”divcls”>
        <div align=”center” style=”vertical-align:middle;”>
            <input type=”text” class=”txtcls” value=”<?=$_REQUEST[‘url’]?>” name=”url” id=”url” placeholder=”Enter Search URL here….” />
            <button title=”Submit” class=”styled-button button-01″ type=”submit”>Submit</button>
        </div>
    </div>
</form>

<div class=”divans”>
<?php

if(isset($_REQUEST[‘url’]) && $_REQUEST[‘url’] != “”)
{
    echo $video_details = $_REQUEST[‘url’];
   
    $feat_image = “”;
    if (preg_match(‘%(?:youtube(?:-nocookie)?.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu.be/)([^”&?/ ]{11})%i’, $video_details, $match)){
        $video_id = $match[1];
}
     
    if($video_id != “”){
    ?>
      <br/><br/><hr/><br/>
     
         <a href=”http://img.youtube.com/vi/<?php echo $video_id;?>/0.jpg” target=”_blank” >
              http://img.youtube.com/vi/<?php echo $video_id;?>/0.jpg</a>
      </a>   
      <br/><br/><hr/><br/>
     
         <a href=”http://img.youtube.com/vi/<?php echo $video_id;?>/1.jpg” target=”_blank” >
      http://img.youtube.com/vi/<?php echo $video_id;?>/1.jpg
      </a>
         <br/><br/><hr/><br/>
     
         <a href=”http://img.youtube.com/vi/<?php echo $video_id;?>/2.jpg” target=”_blank” >
        http://img.youtube.com/vi/<?php echo $video_id;?>/2.jpg
         </a>
     
      <br/><br/><hr/><br/>
      <a href=”http://img.youtube.com/vi/<?php echo $video_id;?>/3.jpg” target=”_blank” >
         http://img.youtube.com/vi/<?php echo $video_id;?>/3.jpg
      </a>
    <?   
    }
   
}
?>
</div>

V!ral

Developer, Technology aficionado, Beer Lover and founder of codify.club Network. Who shares a keen interest about website development, health issues, cancer awareness and other fun stuff.

Add comment

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.

Most popular

Most discussed