写一个函数,尽可能高效的,从一个标准 url 里取出文件的扩展名?


function getExt($url){
   $arr = parse_url($url);
 
   $file = basename($arr['path']);
   $ext = explode(".",$file);
   return $ext[1];
}
$url = "http://www.sina.com.cn/abc/de/fg.php?s=b&c=10.8&s=18.6&ss=18.6";
echo getExt($url);
=------
$url = "http://www.sina.com.cn/abc/de/fg.php?s=b&c=10.8&s=18.6&ss=18.6";
$a = explode("/",$url);
$c = explode("?",$a[count($a)-1]);
$b = explode(".",$c[0]);
print($b[1]);

你可能感兴趣的:(url)