At work, we often encounter the need to obtain the file extension. Here I will summarize the following methods for you. (Criticisms and corrections welcome)
Method 1
Function getFileExtend_1($fileName){
$retval="";
$pt=strtpos($fileName,".");
if($pt){
$retval=substr($fileName,$pt+1,strlen($fileName)-$pt);
}
if($retval!==""){
return $retval;
}
return false;
}
?>
Method 2
Function getFileExtend_2($fileName){
$extend = pathinfo($fileName);
$extend = strtolower($extend['extension']);
if(is_string($extend)){
return $extend;
}
return false;
}
?>
Method 3
Function getFileExtend_3($fileName){
$extend =explode(".",$fileName);
$va=count($extend)-1;
$extend =$extend[$va];
if(is_string($extend)){
return $extend;
}
return false;
}
?>