![]() |
VOOZH | about |
The pathinfo() is an inbuilt function which is used to return information about a path using an associative array or a string.
The returned array or string contains the following information:
The path and options are sent as a parameters to the pathinfo() function and it returns an associative array containing the following elements directory name, basename, extension if the options parameter is not passed.
Syntax:
pathinfo(path, options)
Parameters Used:
The pathinfo() function in PHP accepts two parameters.
Return Value:
It returns an associative array containing the following elements directory name, basename, extension if the options parameter is not passed.
Errors And Exceptions:
Examples:
Input : print_r(pathinfo("/documents/gfg.txt"));
Output : Array
(
[dirname] => /documents
[basename] => gfg.txt
[extension] => txt
)
Input : print_r(pathinfo("/documents/gfg.txt", PATHINFO_DIRNAME));
Output : /documents
Input : print_r(pathinfo("/documents/gfg.txt", PATHINFO_EXTENSION));
Output : txt
Input : print_r(pathinfo("/documents/gfg.txt", PATHINFO_BASENAME));
Output : gfg.txt
Below programs illustrate the pathinfo() function.
Suppose there is a file named "gfg.txt"
Program 1
Output:
Array ( [dirname] => /documents [basename] => gfg.txt [extension] => txt )
Program 2
Output:
/documents
Program 3
Output:
txt
Program 4
Output:
gfg.txt
Reference:
https://www.php.net/manual/en/function.pathinfo.php