url 取出文件扩展名
/*
*url 取出文件扩展名
*/
//方法一
function getExt1($url) {
$arr = parse_url($url);
$file = basename($arr['path']);
$ext = explode('.', $file);
return $ext[count($ext)-1];
}
$path = 'http://www.sina.com.cn/abc/de/fg.php?id=1';
echo getExt1($path);//php
echo '<br/>';
//方法二
function getExt2($url) {
$url = basename($url);
$post1 = strpos($url,'.');
$post2 = strpos($url,'?');
if(strstr($url,'?')) {
return substr($url, $post1+1,$post2-$post1-1);
} else {
return substr($url, $post1);
}
}
echo getExt2($path);//php
echo '<br/>';
//方法三
function getExt3($file) {
return pathinfo($file,PATHINFO_EXTENSION);
}
echo getExt3($path);//php?id=1
echo '<br/>';
//方法四
$info = explode('.', $path);
echo end($info);
echo "<br/>";