PHP获取文件后缀的几种方法

kyle 2016-11-24 958次浏览 0条评论 0 打赏作者 0 0
//使用时需注意:方法/函数名称不能重复,如有重复请自行自改

//First
function get_extension($file)
{
    $file = explode('.', $file);
    return end($file);
}

//Second
function get_extension($file)
{
    return substr(strrchr($file, '.'), 1);
}
 
 
//Third
function get_extension($file){
    return pathinfo($file)['extension'];
}
 
 
//Fourth
function get_extension($file)
{
    return substr($file, strrpos($file, '.') + 1);
}
 
//Fifth
function get_extension($file)
{
    $file = preg_split('/\./', $file);
    return end($file);
}

//Sixth
function   get_extension($file){
    $file = strrev($file);
    return strrev(substr($file,0,strpos($file,'.')));
}
 
//Seventh
function get_extension($file)
{
     return pathinfo($file, PATHINFO_EXTENSION);
}

//Eighth
function get_extension($file)
{
      preg_match_all('/\.[a-zA-Z0-9]+/',$file,$data);
      return !empty($data[0])?substr(end($data[0]),1):'';
}
 
//Ninth
function get_extension($file){
     return str_replace('.','',strrchr($file,'.'));
}
0

0 条评论

    没有找到数据。

发表评论

kyle
土豪

kyle

注册时间:2016-10-28
最后登录:1个月前
发布
带到手机上看