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

How to get file extension in PHP_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:23:05
Original
904 people have browsed it

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 of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template