Sometimes additional parameters are added to the URL. In this case, we can first delete the parameter section, and then we can use the pathinfo () function built into PHP to get the image name from the URL.
$url = 'http://images.fitnessmagazine.mdpcdn.com/sites/story/shutterstock_65560759.jpg?itok=b8HiA95H';
Make sure that parameters are added to the image URL.
if (strpos($url, '?') !== false) { $t = explode('?',$url); $url = $t[0]; }
The resulting url variable now contains
http://images.fitnessmagazine.mdpcdn.com/sites/story/shutterstock_65560759.jpg
Use pathinfo () to get the information you need.
$pathinfo = pathinfo($url); echo $pathinfo['filename'].'.'.$pathinfo['extension'];
This will give shutterstock_65560759.jpg as output.
Sinha
source share