Home  >  Article  >  Backend Development  >  How to use php pathinfo function?

How to use php pathinfo function?

青灯夜游
青灯夜游Original
2019-05-30 10:40:253110browse

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 php pathinfo function?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn