获取文件名后缀的方法
function ext1($str){ // $info = pathinfo($str); // return $info['extension']; return pathinfo($str, PATHINFO_EXTENSION); } echo ext1('test.abc.html');
function ext2($str){ $arr = explode('.',$str); $count = count($arr); return $arr[$count-1]; } echo ext2('test.abc.html');
function ext3($str){ return trim(strrchr($str,'.'),'.'); } echo ext3('test.abc.html');
function ext4($str){ while(strpos($str,'.')){ $num = strpos($str,'.'); $str = trim(substr($str,$num),'.'); // echo $str;exit; } return $str; } echo ext4('test.abc.html'); echo "<hr>";
function ext5($str){ while(strstr($str,'.')){ $str = trim(strstr($str,'.'),'.'); // echo $str;exit; } return $str; } echo ext5('test.abc.html');