一、字符串截取获得
function getExtend($filename)
{
$len=strlen($filename);
$pos=strrpos($filename,'.');
return $extend=mb_substr($filename,$pos+1,$len-$pos,'gb2312');
}
二、使用内置方法获得
function getExtend($filename)
{
$extend=pathinfo($filename);
/* $filename='hello.asp.img';
* Array ( [dirname] => . [basename] => hello.asp.img
* [extension] => img [filename] => hello.asp )
* print_r($extend);
*/
return $extend['extension'];
}
三、使用explode分割数组获取
function getExtend($filename)
{
$arr=explode('.',$filename);//Array ( [0] => hello [1] => asp [2] => img )
$count=count($arr);
echo $arr[$count-1];
}
四、同上
function getExtend($filename)
{
$arr=explode('.',$filename);
return (end($arr));
}