Home > Backend Development > PHP Tutorial > 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
Release: 2016-07-13 17:18:41
Original
1121 people have browsed it

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);
Copy after login


2. Method 2 for searching and intercepting strings


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


3. Method of array segmentation


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


4. Use pathinfo to directly parse


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


5. Use the second parameter of pathinfo


$extension=pathinfo($file, PATHINFO_EXTENSION);
Copy after login


6. Use finfo_file function


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


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...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template