面试题20从一个标准URL里取出文件的扩展名
面试题20 从一个标准URL里取出文件的扩展名
例如ttp://www.sina.com.cn/abc/de/fg.html?id=1,需要取出html。
【分析】
<?php
function getExt($url){
$arr = parse_url($url);
$file = basename($arr["path"]);
$ext = explode(".",$file);
return $ext[1];
}
echo getExt("http://www.sina.com.cn/abc/de/fg.html?id=1")
?>
