php怎么获取文件扩展名
lewis
2017-12-08
18次阅读
要获取文件扩展名,可以使用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
以上两种方法都可以获取文件的扩展名。

发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。