php怎么获取文件扩展名

   2025-02-15 6640
核心提示:要获取文件扩展名,可以使用PHP的pathinfo()函数或者explode()函数。使用pathinfo()函数:$file = 'example.txt';$ext

要获取文件扩展名,可以使用PHP的pathinfo()函数或者explode()函数。

使用pathinfo()函数:

$file = 'example.txt';$ext = pathinfo($file, PATHINFO_EXTENSION);echo $ext; // 输出:txt

使用explode()函数:

$file = 'example.txt';$ext = explode('.', $file);$ext = end($ext);echo $ext; // 输出:txt

以上两种方法都可以获取文件的扩展名。

 
 
更多>同类维修知识
推荐图文
推荐维修知识
点击排行
网站首页  |  关于我们  |  联系方式  |  用户协议  |  隐私政策  |  网站留言