1: string basename (string path [, string suffix]);
A string containing a full path pointing to a file is provided. This function returns the basic file name. If the file name ends with suffix, this part will also be removed.
In Windows, both slash (/) and backslash () can be used as path separators. It is a slash (/) in other environments (/).
Example 1. basename () example
The code is as follows:
<? Php
$ Path = Web page creation tutorial http://www.111cn.net, keep this tag "/home/httpd/html/index. php ";
$ File = basename ($ path); // $ fileissetto "index. php"
$ File = basename ($ path, ". php"); // $ fileissetto "index"
?>
2: string dirname (string path );
The parameter is a file path string and returns the directory after removing the file name.
The path of _ FILE _ is the FILE where the current code is located.
Dirname (_ FILE _); the directory name at the top of the FILE is obtained.
Dirname (_ FILE _); the directory name of the FILE's layer is obtained.
Example
The code is as follows:
<? Php
Echo dirname ("c:/testweb/home. php ");
Echo dirname ("/testweb/home. php ");
?> Output:
C:/testweb
/Testweb
The parameter is a file path string. It returns an array containing three parts: directory name, file name, and extension, which are referenced by dirname, basename, and extension.
3: array pathinfo ($ path );
Example 1
The code is as follows:
<? Php
Print_r (pathinfo ("/testweb/test.txt "));
?>
The code is as follows:
Array
(
[Dirname] =>/testweb
[Basename] => test.txt
[Extension] => txt
)
Example 2
Output:
The code is as follows:
<? Php
Print_r (pathinfo ("/testweb/test.txt", PATHINFO_BASENAME ));
?>
Output:
The code is as follows:
Test.txt