PHP 文件扩展名 获取函数

yipeiwu_com5年前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如何将XML转成数组

如果你使用 curl 获取的 xml data xml=simplexmlloadstring(data); data[′tk′]=jsondecode(jsonencode(xml),...

php数组函数序列之array_search()- 按元素值返回键名

array_search()定义和用法 array_search() 函数与 in_array() 一样,在数组中查找一个键值。如果找到了该值,匹配元素的键名会被返回。如果没找到,则返回...

PHP文件读写操作之文件写入代码

在PHP网站开发中,存储数据通常有两种方式,一种以文本文件方式存储,比如txt文件,一种是以数据库方式存储,比如Mysql,相对于数据库存储,文件存储并没有什么优势,但是文件读写操作在基...

WordPress中获取页面链接和标题的相关PHP函数用法解析

get_permalink()(获取文章或页面链接) get_permalink() 用来根据固定连接返回文章或者页面的链接。在获取链接时 get_permalink() 函数需要知道要...

PHP使用preg_split和explode分割textarea存放内容的方法分析

本文实例讲述了PHP使用preg_split和explode分割textarea存放内容的方法。分享给大家供大家参考,具体如下: 今天有个紧急的bug,说是后台在配置了白名单后,在手机端...