Course Recommendation:
PHP pathinfo() Function
Definition and Usage
The pathinfo() function returns the information of the file path in the form of an array.
Syntaxpathpathinfo(,)
Parameters | Description |
---|---|
path | Required. Specifies the path to be checked. |
process_sections |
Optional. Specifies the array elements to be returned. The default is all. Possible values:
|
Description
pathinfo() returns an associative array containing path information.
It includes the following array elements:
- [dirname]
- [basename]
- [extension]
Tips and Comments
Note:If all units are not required, the pathinfo() function returns a string.
Instance
Example 1
<?php print_r(pathinfo("/testweb/test.txt")); ?>
Output:
Array ( [dirname] => /testweb [basename] => test.txt [extension] => txt )
Example 2
<?php print_r(pathinfo("/testweb/test.txt",PATHINFO_BASENAME)); ?>
Output:
test.txt