What is the function of PHP dirname ()?
The PHP dirname () function is the part of the directory that returns the file path. It gives a string containing a full path to a file, returning the name of the directory after removing the file name. The syntax is as follows
Grammar:
String DirName (String $path)
Detailed parameters:
The parameter path is a path, which is the path we need to check.
PS: In Windows, slashes (/) and backslashes (\) can be used as directory separators. In other environments it is a slash (/).
The return value of the PHP dirname () function
Returns the parent directory of path. If there is no slash in Path, a point ('. ') is returned. ), which represents the current directory. Otherwise, the string that/component the end of Path (the last slash and later) is removed.
Example
Example One
<?phpecho dirname ("c:/testweb/home.php"). "<br/>"; Echo dirname ("/testweb/home.php");? >
Code Run Result:
Example Two
Suppose there is now a path to the file under the D:/www/images/1.jpg path: We use the PHP dirname () function to get the directory portion of this file, the code is as follows:
<?php$apth= ' d:/www/images/1.jpg '; echo dirname ($apth). "<br/>"; Echo dirname ("/www/images/home.php");? >
The results of the code run as
"Related articles recommended":
Detailed PHP pathinfo () function get file path information