Access our premium support and let us know your problems, we will help you solve them.

0
No products in the cart.

Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • in reply to: How can I get the name of the image from url? #9934
    blanksinha
    Participant

    Sometime url has additional parameters appended to it. In such scenario we can remove the parameter section first and then we can use the PHP’s inbuilt pathinfo() function to get the image name from the url.

    $url = 'http://images.fitnessmagazine.mdpcdn.com/sites/story/shutterstock_65560759.jpg?itok=b8HiA95H';
    

    Check if the image url has parameters appended.

    if (strpos($url, '?') !== false) {
        $t = explode('?',$url);
        $url = $t[0];            
    }      
    

    The resulting url variable now contain

    http://images.fitnessmagazine.mdpcdn.com/sites/story/shutterstock_65560759.jpg

    Use the pathinfo() to retrieve the desired details.

    $pathinfo = pathinfo($url);
    echo $pathinfo['filename'].'.'.$pathinfo['extension'];
    

    This will give shutterstock_65560759.jpg as output.

Viewing 1 post (of 1 total)