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

怪我咯
Release: 2023-03-07 21:14:02
Original
3064 people have browsed it

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)
Copy after login

Parameter details:

Parameter Description
pathRequired. 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"));
?>
Copy after login

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));
?>
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template