Home > Article > Backend Development > Detailed explanation of the usage of php dirname() function to obtain file information
What is the function of php dirname() function?
php The 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
Syntax:
string dirname ( string $path )
Parameter details:
The parameter path is a path, and this path is the path we need to check.
PS: In Windows, both slash (/) and backslash (\) can be used as directory separators. In other circumstances it is a slash (/).
The return value of php dirname() function
Returns the parent directory of path. If there is no slash 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 part).
Example
Example 1
<?php echo dirname("c:/testweb/home.php") . "<br />"; echo dirname("/testweb/home.php"); ?>
Code running result:
Example 2
Assume that there is a file path under the path D:/WWW/images/1.jpg: We use the php dirname() function to get the file In the directory part, the code is as follows:
<?php $apth='D:/WWW/images/1.jpg'; echo dirname($apth) . "<br />"; echo dirname("/WWW/images/home.php"); ?>
The code running result is as shown below
##[Recommended related articles]:
Detailed explanation of php pathinfo() function to obtain file path information
The above is the detailed content of Detailed explanation of the usage of php dirname() function to obtain file information. For more information, please follow other related articles on the PHP Chinese website!