PHP pathinfo()Functions
Complete PHP Filesystem Reference Manual
Definition and Usage
The pathinfo() function returns information about a file path as an array.
The returned array elements are as follows:
- [dirname]: Directory path
- [basename]: File name
- [extension]: File extension
- [filename]: File name without extension
Syntax
pathinfo(path,options)
| Parameter | Description |
|---|---|
| path | Required. Specifies the path to be checked. |
| options | Optional. Specifies the array elements to return. Default is all. Possible values:
|
Tips and Notes
Note:If not all elements are requested, the pathinfo() function returns a string.
Examples
Example 1
print_r(pathinfo("/testweb/test.txt"));
The above code will output:
Array
(
[dirname] => /testweb
[basename] => test.txt
[extension] => txt
[filename] => test
)
Example 2
print_r(pathinfo("/testweb/test.txt",PATHINFO_BASENAME));
The above code will output:
test.txt
Other Extensions