Home  >  Article  >  Backend Development  >  Detailed explanation of the usage of php dirname() function to obtain file information

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

怪我咯
怪我咯Original
2017-05-24 11:36:492438browse

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:

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

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=&#39;D:/WWW/images/1.jpg&#39;;
echo dirname($apth) . "<br />";

echo dirname("/WWW/images/home.php");
?>

The code running result is as shown below

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

##[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!

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