Home > Article > Backend Development > 6 ways to get the extension of a file in PHP_PHP Tutorial
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);
$extension=substr($file, strrpos($file, '.')+1);
$extension=end(explode('.', $file));
$info = pathinfo($file); $extension=$info['extension'];
$extension=pathinfo($file, PATHINFO_EXTENSION);
$finfo = finfo_open(FILEINFO_MIME_TYPE); $extension = finfo_file($finfo, $file) ; echo $extension; finfo_close($finfo);