header("Content-type:text/html;charset=utf-8");
//需求:从一个url里取出文件的扩展名
/*
* 方案1
* 函数名:getExt1
* 说明:从url里取出文件的扩展名
*/
function getExt1($url){
// 解析URL,array('scheme' => string 'http','host' => string 'blog.51cto.com','path' => string '/suyanzhu/2299545.jpg');
$arr = parse_url($url);
// 获取文件路径
$file = basename($arr['path']);
// 字符串拆分
$ext = explode('.', $file);
// 返回扩展名
return $ext[count($ext)-1];
}
var_dump(getExt1("https://blog.51cto.com/suyanzhu/2299545.jpg"));
转载于:https://blog.51cto.com/suyanzhu/2299968