日期:2014-05-17 浏览次数:20473 次
$webimage = 'http://pcdn.500px.net/5953805/d0dd841969187f47e8ad9157713949b4b95b3bda/4.jpg?1333782904356'; $pieces = explode("/", $webimage); $pathend = end($pieces); $imageinfo = @getimagesize($webimage); $imagetype= $imageinfo['mime']; if($imagetype=='image/jpeg'){ if(stripos($pathend,'.jpg')==false){ $newpathend = $pathend.'.jpg'; // if image end is't '.jpg', add '.jpg' }else if(stripos($pathend,'.jpeg')==0){ $newpathend = $pathend.'.jpeg'; // if image end is't '.jpg', add '.jpeg' }else{ $newpathend = $pathend;// if image end is '.jpg' or '.jpeg', do not change } } if($imagetype=='image/png'){ if(stripos($pathend,'.png')==false){ $newpathend = $pathend.'.png'; // if image end is't '.png', add '.png' }else{ $newpathend = $pathend;// if image end is '.png', do not change } } if($imagetype=='image/gif'){ if(stripos($pathend,'.gif')==false){ $newpathend = $pathend.'.gif'; // if image end is't '.gif', add '.gif' }else{ $newpathend = $pathend;// if image end is '.gif', do not change } }
$url = "http://pcdn.500px.net/5953805/d0dd841969187f47e8ad9157713949b4b95b3bda/4.jpg?1333782904356"; $url_arr = parse_url($url); echo basename($url_arr['path']);
------解决方案--------------------
$webimage = 'http://pcdn.500px.net/5953805/d0dd841969187f47e8ad9157713949b4b95b3bda/4.jpg?1333782904356'; $pieces = explode("/", $webimage); $fileName = end($pieces); $ar = explode('.', $fileName); preg_match('/^(jpg|jpeg|png|gif){1}\.*/i', $ar[1], $match); $newFileName = $ar[0].'.'.$match[1]; echo $newFileName;