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

Summary of usage of php pathinfo() function to obtain file path information

怪我咯
怪我咯Original
2017-06-02 14:01:523589browse

In php, there is a built-in function pathinfo, which can easily obtain the file extension, file name and other information! The role of the pathinfo() function is to return file path information in the form of an array. This article has compiled some usages and examples of the php pathinfo() function. I hope it will be helpful for everyone to understand the pathinfo() function.

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

The pathinfo() function is in the form of an array Returns file path information. This article mainly introduces some syntax parameters of the php pathinfo() function. pathinfo() returns an associative array containing path information. Includes the following array units: dirname, basename and extension. You can specify which units to return through the parameter options. They include: PATHINFO_DIRNAME, PATHINFO_BASENAME and PATHINFO_EXTENSION. The default is to return all units. If it is not required to obtain all units, this function returns a string.

2.Detailed explanation of the php pathinfo() function to obtain the path, name and other information of the file

In PHP, if you want to pass It is very easy for the function to obtain the path, name, or extension of a file. You can use dirname(), basename(), pathinfo() and other methods to obtain the corresponding information. This article mainly introduces the different file information returned by the three functions pathinfo(), dirname(), and basename()

3.The differences and examples of dirname, basename, and pathinfo functions in php

php dirname function gets the directory part of the given file path, php basename() function gets the file name part of the path, this function is exactly the opposite of dirname() (dirname gets the directory part of the path part). The php pathinfo function is used to parse the path and parse the path into an array. The array includes four values: directory name, complete file name, file extension and file name (excluding file suffix), and the key names of these four values ​​are respectively dirname, basename, extension and filename, we can use these four key names to obtain the directory name, complete file name, file extension and file name values. This article mainly introduces to you in detail the differences and usage examples of these three functions.

4.Using php pathinfo(), parse_url(), basename() functions to parse URL examples

PHP function pathinfo (), parse_url() and basename(), these three are all functions for parsing URLs, but there are some differences. This article lists some examples, hoping that these examples will help everyone understand the use of these three functions more easily.

Methods and techniques

[Related Q&A recommendations]

How to set up nginx to support pathinfo

Are there any benefits to pathinfo?

url - .htaccess hides index.php and uses pathinfo to cause css js loading errors

[Related article recommendations]

thinkphp3.2.X pathinfo ultimate solution under lnmp

pathinfo mode and URL rewriting in ThinkPHP

The above is the detailed content of Summary of usage 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