当前位置:Gxlcms > PHP教程 > php获取文件扩展名的函数

php获取文件扩展名的函数

时间:2021-07-01 10:21:17 帮助过:14人阅读

有时候我们需要获取文件的扩展名,分类文件等原因,下面是php的函数实例代码。

代码如下:

<?php 
$file = "/home/lvyaozu/backup_20080115.txt"; 

for($i=1; $i < 6; $i++) { 
$func = 'get_file_ext_' . $i; 
var_dump($func($file)); 
} 


function get_file_ext_1($file) { 
return strtolower(trim(substr(strrchr($file, '.'), 1))); 
} 

function get_file_ext_2($file) { 
return strtolower(trim(pathinfo($file, PATHINFO_EXTENSION))); 
} 

function get_file_ext_3($file) { 
return strtolower(trim(substr($file, strrpos($file, '.')+1))); 
} 

function get_file_ext_4($file) { 
return strtolower(trim(array_pop(explode('.', $file)))); 
} 

function get_file_ext_5($file) { 
$tok = strtok($file, '.'); 
while($tok !== false) { 
$return = $tok; 
$tok = strtok('.'); 
} 
return strtolower(trim($return)); 
} 
?>

以上就是php 获取文件扩展名的函数的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行