PHP can obtain the file extension in six ways. Yesterday, I talked to a friend in a PHP chat group (276167802, verification: csl, if you are interested, you can join in and discuss it) and mentioned six methods for PHP to get the file extension, now I took it out yesterday and talked with a friend in the PHP chat group (276167802, verification: csl. if you are interested, you can join in for discussion ).
PHPYou can use the following six methods to obtain the file extension:
1. string search and truncation methods
$extension=substr(strrchr($file, '.'), 1);
2. Method 2 for string search and truncation
$extension=substr($file, strrpos($file, '.')+1);
3. array partitioning
$extension=end(explode('.', $file));
4. direct parsing using pathinfo
$info = pathinfo($file);$extension=$info['extension'];
5. use the second parameter of pathinfo
$extension=pathinfo($file, PATHINFO_EXTENSION);
6. use the finfo_file function
$finfo = finfo_open(FILEINFO_MIME_TYPE);$extension = finfo_file($finfo, $file) ;echo $extension;finfo_close($finfo);
Token, I talked to a friend in the PHP chat group (276167802, verification: csl, if you are interested, you can join in and discuss it) and mentioned six methods for PHP to get the file extension, now come up...