php取得文件扩展名的三种方法(改进版)
时间:2021-07-01 10:21:17
帮助过:16人阅读
//取文件的扩展名 - //by http://bbs.it-home.org
//method 1 - function get_file_ext_1($fileName){
- $retval="";
- $pt=strtpos($fileName,".");
- if($pt){
- $retval=substr($fileName,$pt+1,strlen($fileName)-$pt);
- }
- if($retval!==""){
- return $retval;
- }
- return false;
- }
//method two - function get_file_ext_2($fileName){
- $extend = pathinfo($fileName);
- $extend = strtolower($extend['extension']);
- if(is_string($extend)){
- return $extend;
- }
- return false;
- }
//method three - function get_file_ext_3($fileName){
- $extend =explode(".",$fileName);
- $va=count($extend)-1;
- $extend =$extend[$va];
- if(is_string($extend)){
- return $extend;
- }
- return false;
- }
- ?>
|