一.pathinfo()函数 php
pathinfo()函数返回一个包含了文件信息的数组,数组中有四个元素,分别是dirname、basename、extension、filename。数组
举例:函数
<?phpio
//pathinfo函数用法function
$path = "/www/jbxue/images/logo.jpg";file
$fileArr = pathinfo($path);方法
print_r($fileArr);im
//输出结果:Array ( [dirname] => /www/jbxue/images [basename] => logo.jpg [extension] => jpg [filename] => logo )di
//根据数组的键名就能够得到对应的键值文件
echo $fileArr['filename'];
//输出结果:logo
echo $fileArr['extension'];
//输出结果:jpg
?>
二.另外一种实现方法
function path_info($filepath)
{
$path_parts = array();
$path_parts ['dirname'] = rtrim(substr($filepath, 0, strrpos($filepath, '/')),"/")."/";
$path_parts ['basename'] = ltrim(substr($filepath, strrpos($filepath, '/')),"/");
$path_parts ['extension'] = substr(strrchr($filepath, '.'), 1);
$path_parts ['filename'] = ltrim(substr($path_parts ['basename'], 0, strrpos($path_parts ['basename'], '.')),"/");
return $path_parts;
}
$path=path_info("/www/jbxue/images/logo.jpg");
var_dump($path);