mardi 5 mai 2020

Take value from URL

I create php code for taking value from url like this "https://www.youtube.com/watch?v=sLnwdjQQlIw" , In this URL my php code take value after "v=" which I need. this works perfectly, but if user enter this type URL https://youtu.be/OKuGTy7D52c , so how to take value from this url , I need value after "be/" only and echo videoId here <img src="https://img.youtube.com/vi/<?php echo $videoId; ?>/hqdefault.jpg" below my php code . Anyone help me to solve this problem!!!

<?php
    if(isset($_POST["Search"])){
    $url = $_POST["url"];
    $value = (explode('v=', $url));
    $videoId = $value[1];
    }
    ?>
# My search box from where I take URL  

<form method="post" class="form-group">
                    <input name="url" type="url" class="form-control form-control-lg mb-3" placeholder="https://www.youtube.com/watch?v=9a5TF2U-Fa4" required>
                    <button style="background-color:#f2ae06;border:none" name="Search" class="btn btn-primary btn-lg btn-block">Get</button>



Aucun commentaire:

Enregistrer un commentaire