php中几种获取文件后缀名的方法
php中几种获取文件后缀名的方法详细介绍
php中有多种获取文件后缀名的方法,比如使用substr()函数与pathinfo()函数等,下面就来介绍几种php中获取文件后缀名的方法。
示例1:
php substr() 函数获取文件后缀名function get_extension($file){
return substr(strrchr($file, '.'), 1);
}
示例2:function get_extension2($file){
return substr($file, strrpos($file, '.')+1);
}
示例3:
php explode() 函数获取文件的后缀名function get_extension3($file){
return end(explode('.', $file));
}
示例4:
php pathinfo() 函数获取文件的后缀名!function get_extension4($file){
$info = pathinfo($file);
return $info['extension'];
}
示例5:
php pathinfo() 函数中的第二个参数的值如果为 PATHINFO_EXTENSION ,可以直接返回文件的后缀名!function get_extension5($file){
return pathinfo($file, PATHINFO_EXTENSION);
}