Obtain details regarding a file path:
<?php print_r(pathinfo(“/testweb/test.txt”)); ?> |
The following is the result of the code above:
Array ( [dirname] => /testweb [basename] => test.txt [extension] => txt ) |
A file path’s information is returned by the pathinfo() function.
pathinfo(path, options) |
Parameter |
Description |
path |
Essential. indicates the path that has to be examined. |
options |
Not required. indicates the array element to be returned. It returns all elements if nothing is given. • PATHINFO_EXTENSION – return only extension; • PATHINFO_BASENAME – return only basename |
Return Value: |
It returns an associative array containing dirname, basename, extension, and filename if the option parameter is not supplied. The requested element is returned in a string if the option parameter is supplied. When something fails, FALSE |
PHP Version: |
4.0.3+ |
PHP Changelog: |
PATHINFO_FILENAME was added in PHP 5.2. |
Obtain details regarding a file path:
<?php print_r(pathinfo(“/testweb/test.txt”,PATHINFO_BASENAME)); ?> |
The following is the result of the code above:
test.txt |