// 要求:dir/aaa.jpg 获取.jpg或者jpg
// 必须使用php自带的函数进行处理,方法不能明显重复。
$fileName = 'aaa.jpg';
// .jpg
function getExt1($fileName){
return strrchr($fileName, '.');
}
// .jpg
function getExt2($fileName){
return substr($fileName, strrpos($fileName, '.'));
}
// jpg
function getExt3($fileName){
return array_pop(explode('.', $fileName));
}
// jpg
function getExt4($fileName){
$p = pathinfo($fileName);
return $p['extension'];
}
// jpg
function getExt5($fileName){
return strrev(substr(strrev($fileName), 0, strpos(strrev($fileName), '.')));
}