pathinfo() is a built-in function in PHP that returns information about the file path using an associative array or string. The syntax is pathinfo(path,options), which returns an associative array containing path information.
How to use the pathinfo() function?
The pathinfo function returns file path information in the form of an array.
Syntax:
pathinfo(path,options)
Parameters: The pathinfo() function accepts two parameters.
path: required. Specifies the path to be checked.
process_sections: Optional. Specifies the array elements to be returned. The default is all.
Possible values:
● PATHINFO_DIRNAME - only returns dirname.
●PATHINFO_BASENAME - Only basename is returned.
● PATHINFO_EXTENSION - only returns extension.
Return value: Returns an associative array containing path information. If the options parameter is not passed, include the following array elements: [dirname], [basename], [extension]
php pathinfo() function example
<?php $file = "/phpstudy/WWW/index.php"; print_r(pathinfo($file)) ; ?>
Output:
Array ( [dirname] => /phpstudy/WWW [basename] => index.php [extension] => php [filename] => index )
The above is the detailed content of How to use php pathinfo function?. For more information, please follow other related articles on the PHP Chinese website!