昨天, 和一个朋友在PHP交流群(276167802, 验证:csl,有兴趣的话可以加入进来一起讨论)里提到PHP 获取文件的扩展名的6种方法,现在拿出来和大家分享一下:
1、字符串查找和截取的方法
$extension=substr(strrchr($file, '.'), 1);
2、字符串查找和截取的方法二
$extension=substr($file, strrpos($file, '.')+1);
3、数组分割的方法
$extension=end(explode('.', $file));
4、使用pathinfo直接解析的方法
$info = pathinfo($file); $extension=$info['extension'];
5、使用pathinfo的第二个参数
$extension=pathinfo($file, PATHINFO_EXTENSION);
6、使用finfo_file函数
$finfo = finfo_open(FILEINFO_MIME_TYPE); $extension = finfo_file($finfo, $file) ; echo $extension; finfo_close($finfo);

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)