PHP dirname() function returns file directory usage summary

怪我咯
Release: 2023-03-08 06:02:01
Original
3915 people have browsed it

php dirname() function returns the directory part of the file path. It gives a string containing the full path to a file and returns the directory name minus the filename. The usage is very simple. This article collects several articles on the usage of PHP's function to return the file directory. I hope it will be helpful for everyone to understand the function of PHP to return the file directory.

1.Detailed explanation of the usage of php dirname() function to obtain file information

php dirname() function returns the directory part of the file path. It gives a string containing the full path to a file and returns the directory name minus the filename. The syntax is as follows

string dirname ( string $path )
Copy after login

The parameter path is a path, and this path is the path we need to check. It returns the parent directory of path. If there are no slashes in path, a dot ('.') is returned, indicating the current directory. Otherwise, the string returned is the string after removing the /component at the end of path (the last slash and the following parts).

2.Detailed explanation of dirname, realpath, __FILE__ functions related to PHP paths

PHP dirname() function returns file directory usage summary

This article mainly introduces It mainly introduces the three functions dirname, realpath, and __FILE__ related to PHP paths. Students who are interested in PHP tutorials can refer to them. For example: the program root directory is in: E:\wamp\www. If called in index.php, E:\wamp\www\index.php will be returned. dirname returns the parent directory of the current directory or the directory where the current file is located (without / at the end), is generally used in conjunction with __FILE__

3. Parsing the application of php dirname() and __FILE__ constants

__FILE__ represents the absolute path of the current file including the file name, dirname(__FILE__) represents the absolute path of the current file, and basename(__FILE__) represents The file name of the current file is dirname(__FILE__)."/f/".basename(__FILE__)

, which means that the file name is dirname(__FILE__) in the f directory under the directory where the current file is located, require Indicates that the file is included in this file.

4.Analysis of usage examples of __FILE__, dirname and basename in PHP

The examples in this article describe the usage of __FILE__, dirname and basename in PHP. Share it with everyone for your reference. The specific method is as follows: In php, __FILE__ is the full path and file name of the currently running file. If used in an included file, the included file name is returned. This is a magic variable (predefined constant), We can use dirname and basename to get the file directory or file name.

5.Differences and examples of dirname, basename, pathinfo functions in php

php The dirname function gets the directory part of a given file path, and the 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). 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 the differences and usage examples of these three functions in detail.

【Related Q&A recommendations】

Functions such as dirname in php cannot handle Chinese paths

Use path .join splicing _dirname with the required directory, error _dirname is not a function?

##[dirname entry]

dirname

【Related article recommendations】

php dirname, basename, pathinfo parsing directory path

The above is the detailed content of PHP dirname() function returns file directory usage summary. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!