写一个函数,尽可能高效的,从一个标准 url 里取出文件的扩展名 例如: http://www.sina.com.cn/abc/de/fg.php?id=1 需要取出 php 或 .php
1 回答

九州编程
TA贡献1785条经验 获得超4个赞
答案1:
function getExt($url){
$arr = parse_url($url);
$file = basename($arr['path']);
$ext = explode(".",$file);
return $ext[1];
}
答案2:
function getExt($url) {
$url = basename($url);
$pos1 = strpos($url,".");
$pos2 = strpos($url,"?");
if(strstr($url,"?")){
return substr($url,$pos1 + 1,$pos2 - $pos1 - 1);
} else {
return substr($url,$pos1);
}
}
- 1 回答
- 0 关注
- 539 浏览
添加回答
举报
0/150
提交
取消