Home  >  Article  >  Backend Development  >  6 ways to get the extension of a file in PHP_PHP Tutorial

6 ways to get the extension of a file in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:18:411093browse

Yesterday, a friend and I mentioned in the PHP exchange group (276167802, verification: csl, if you are interested, you can join and discuss together) PHP 6 ways to get the extension of a file, now I will share it with everyone Share it:

1. Methods of searching and intercepting strings


$extension=substr(strrchr($file, '.'), 1);


2. Method 2 for searching and intercepting strings


$extension=substr($file, strrpos($file, '.')+1);


3. Method of array segmentation


$extension=end(explode('.', $file));


4. Use pathinfo to directly parse


$info = pathinfo($file);
$extension=$info['extension'];


5. Use the second parameter of pathinfo


$extension=pathinfo($file, PATHINFO_EXTENSION);


6. Use finfo_file function


$finfo = finfo_open(FILEINFO_MIME_TYPE);
$extension = finfo_file($finfo, $file) ;
echo $extension;
finfo_close($finfo);


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/621640.htmlTechArticleYesterday, I was in the PHP exchange group (276167802, verification: csl) with a friend. If you are interested, you can join and discuss ) mentioned 6 ways to get the file extension in PHP, now take out...
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