Home >php教程 >php手册 >PHP如何获得文件扩展名

PHP如何获得文件扩展名

WBOY
WBOYOriginal
2016-06-13 09:28:591203browse

PHP如何获得文件扩展名

   在工作中,经常遇到需要获得文件的扩展名,这里我给大家总结以下几个方法。(欢迎批评指正)

  方法一

  

  function getFileExtend_1($fileName){

  $retval="";

  $pt=strtpos($fileName,".");

  if($pt){

  $retval=substr($fileName,$pt+1,strlen($fileName)-$pt);

  }

  if($retval!==""){

  return $retval;

  }

  return false;

  }

  ?>

  方法二

  

  function getFileExtend_2($fileName){

  $extend = pathinfo($fileName);

  $extend = strtolower($extend['extension']);

  if(is_string($extend)){

  return $extend;

  }

  return false;

  }

  ?>

  方法三

  

  function getFileExtend_3($fileName){

  $extend =explode(".",$fileName);

  $va=count($extend)-1;

  $extend =$extend[$va];

  if(is_string($extend)){

  return $extend;

  }

  return false;

  }

  ?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn