We talked earlier about using the PHP pathinfo () function to return the file path information, the PHP dirname () function is the directory part of the return file path, this article mainly introduces the use of
php basename () functionReturns the file name in the path
Part.
The PHP basename () function syntax is as follows:
BaseName (Path,suffix)
Detailed parameters:
Parameters |
Description |
Path |
Necessary. Specifies the path to check. |
Suffix |
Optional. Specifies the file name extension. If the file has a file name extension, this extension will not be displayed. |
Description
The PHP basename () function gives a string containing a full path to a file, which returns the basic file name. If the file name ends in suffix, then this part will be removed as well. In Windows, slash (/)
and backslashes (\) can be used as directory separators. Slash (/) in other environments
Example
<?php$path = "www/testweb/home.php";//Display file name and file name extension echo basename ($path). " <br/> ";//display filename does not have file name extension echo basename ($path,". php ");? >
Code Explanation:
Our first echo used without the suffix parameter, returned with the file name and filename extension information, and two echo, with the suffix parameter PHP, so returned is the file name, no extension name.
The result of the code operation is as follows:
"Related articles recommended":
1. Detailed php pathinfo () function get file path information
2. Detailed php dirname () function get file information usage