PHP 文件扩展名 获取函数

yipeiwu_com6年前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));
}
?>

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lvyaozu/archive/2009/06/03/4237628.aspx

相关文章

PHP页面间参数传递的四种方法详解

我们定义page01.php和page02.php两个php文件,将page01中的内容想办法传递到page02,然后供我们继续使用。--------------------------...

PHP-FPM运行状态的实时查看及监控详解

PHP-FPM运行状态的实时查看及监控详解

前言 大家都知道PHP-FPM内置了状态页,开启后可查看PHP-FPM的详细运行状态,给PHP-FPM优化带来帮助。 打开php-fpm.conf,配置php-fpm状态页选项 p...

PHP 取多维数组指定一列的函数

PHP中对多维数组特定列的提取,是个很常用的功能,有一个专用的函数array_column()用PHP内置的 array_column() 函数是最简单的方法,限制是PHP版本必须是5.5.0及以上版...

PHP学习笔记之三 数据库基本操作

下面是在Linux上登录mysql,创建数据库和创建表的过程。 yin@yin-Ubuntu10:~$ mysql -u root -p Enter password: Welcome...

php中大括号作用介绍

一、不管什么程序,function name(){}, for(){}, ….太多了,不说也知道做什么用了。 二、$str{4}在字符串的变量的后面跟上{}刚大括号和中括号一样都是把某个...