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 正则表达式之正则处理函数小结(preg_match,preg_match_all,preg_replace,preg_split)

前面我们已经学习了正则表达式的基础语法,包括了定界符、原子、元字符和模式修正 符。实际上正则表达式想要起作用的话,就必须借用正则表达式处理函数。本节我们就来介绍一下PHP中基于perl的...

php算开始时间到过期时间的相隔的天数

复制代码 代码如下://mktime = mktime($hours,minute,seconds,month,day,years) $start_time = mktime(0,0,0...

PHP 小心urldecode引发的SQL注入漏洞

Ihipop 学校的 Discuz X1.5 论坛被黑,在那里吵了一个下午。Google 一下“Discuz! X1-1.5 notify_credit.php Blind SQL in...

PHP学习笔记 IIS7下安装配置php环境

PHP学习笔记 IIS7下安装配置php环境

Php如何安装 Php版本的选择 Php在windows下的(php5.4.7)有两种版本: VC9 x86 Non Thread Safe 非线程安全型 以FastCGI模式运行 VC...

php 获取文件行数的方法总结

stream_get_line获取文件行数 <?php $file_path = 'xxx.txt'; //文件路径 $line = 0 ; //初始化行数 //...