php 使用七种以上方式获取一个文件的扩展名

$file_name = 'dir/upload.image.jpg';

var_dump(get_ext7($file_name));

function get_ext1($file_name) {
    return strrchr($file_name, '.');
}

function get_ext2($file_name) {
    return substr($file_name, strrpos($file_name, '.'));
}

function get_ext3($file_name) {
    return array_pop(explode('.', $file_name));
}

function get_ext4($file_name) {
//    $p = pathinfo($file_name);
//    return $p['extension'];
    return pathinfo($file_name, PATHINFO_EXTENSION);
}

function get_ext5($file_name) {
    return preg_replace('/.*(\..*)/', '\\1', $file_name);
}

function get_ext6($file_name) {
    return strrev(substr(strrev($file_name), 0, strpos(strrev($file_name), '.')));
}

function get_ext7($file_name) {
    return end(explode('.', $file_name));
}
前望
原文地址:https://www.cnblogs.com/ybbqg/p/2483082.html