pathinfo() – 返回文件路径的信息
适用版本: php4>=4.0.3
php5
php7
用法:mixed pathinfo ( string $path [, int $options = PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME ] )
注意:pathinfo()没有指定options返回一个关联数组包含有path的信息,如果指定了,将会返回指定元素
返回关联数组还是options取决于options。
实例:
<?php
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');
echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
echo $path_parts['filename'], "\n"; // since PHP 5.2.0
?>
以上例程会输出:
/www/htdocs/inc lib.inc.php php lib.inc
实例 1
<?php
print_r(pathinfo("/testweb/test.txt"));
?>
上面的代码将输出:
Array
(
[dirname] => /testweb
[basename] => test.txt
[extension] => txt
)
实例 2
<?php
print_r(pathinfo("/testweb/test.txt",PATHINFO_BASENAME));
?>
上面的代码将输出:
test.txt