Home >Backend Development >PHP Tutorial >How to get file extension in PHP_PHP Tutorial

How to get file extension in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:23:05887browse

How to obtain the file extension in PHP

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;

 }

 ?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/845131.htmlTechArticleHow to get the file extension in PHP At work, I often encounter the need to get the file extension. Here I will give you Summarize the following methods. (Criticisms and corrections welcome) Method 1 function getF...
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