Home >Backend Development >PHP Tutorial >Detailed explanation of php pathinfo() function to obtain file path information

Detailed explanation of php pathinfo() function to obtain file path information

怪我咯
怪我咯Original
2017-05-24 11:35:423118browse

What does the pathinfo() function do?

In PHP, the pathinfo() function is used to return file path information in the form of an array. His syntax is as follows:

Grammar

pathinfo(path,options)

Parameter details:

Parameter 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:

  • PATHINFO_DIRNAME - Returns only dirname

  • PATHINFO_BASENAME - Returns only basename

  • PATHINFO_EXTENSION - Only return extension

## including the following array elements:

[dirname] :Return the directory part of the file path

[basename]:Return the file name part of the file path
[extension]:Return the type part of the file in the file path

Ps: If it is not required To obtain all units, the pathinfo() function returns a string.

Example

Example 1, use the pathinfo() function to obtain all file path information, the code is as follows

<?php
print_r(pathinfo("/testweb/test.txt"));
?>

Code running results:

Detailed explanation of php pathinfo() function to obtain file path information

[filename]: is the file name of the php file

Example 2, use the pathinfo() function to obtain individual PATHINFO_BASENAME information, the code is as follows :


<?php
print_r(pathinfo("/testweb/test.txt",PATHINFO_BASENAME));
?>

Code running result:

Detailed explanation of php pathinfo() function to obtain file path information

The above is the detailed content of Detailed explanation of php pathinfo() function to obtain file path information. 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