方法一:
$url = "http://www.sina.com.cn/abc/de/fg.php?id=1";
public function getExt($url){
$arr = parse_url($url);
//arr = Array ( [scheme] => http [host] => www.sina.com.cn [path] => /abc/de/fg.php [query] => id=1 )
$file = basename($arr['path']);
$ext = explode('.',$file);
return $ext[count($ext)-1];
}
方法二:
public function getExt2($url){
$basename = basename($url);
$pos1 = strpos($basename,'.');
$pos2 = strpos($basename,'?');
if(strstr($basename,'?')){
$ext = substr($basename,$pos1+1,$pos2-$pos1-1);
return $ext;
}else{
$ext = substr($basename,$pos1);
return $ext;
}
}
网友评论