PHP pathinfo () function
Definition and Usage
pathinfo () function returns an array of information about a file path.
The array element returned are as follows:
- [Dirname]
- [Basename]
- [Extension]
grammar
pathinfo(path,options)
参数 | 描述 |
---|---|
path | 必需。规定要检查的路径。 |
options | 可选。规定要返回的数组元素。默认是 all。 可能的值:
|
Tips and Notes
Note: If not all of the elements of the request, the pathinfo () function returns a string.
Example 1
<?php
print_r(pathinfo("/testweb/test.txt"));
?>
print_r(pathinfo("/testweb/test.txt"));
?>
The code above will output:
Array
(
[dirname] => /testweb
[basename] => test.txt
[extension] => txt
)
(
[dirname] => /testweb
[basename] => test.txt
[extension] => txt
)
Example 2
<?php
print_r(pathinfo("/testweb/test.txt",PATHINFO_BASENAME));
?>
print_r(pathinfo("/testweb/test.txt",PATHINFO_BASENAME));
?>
The code above will output:
test.txt
Complete PHP Filesystem Reference Manual