Let’s take a look at the tutorial below to provide an example of the basename function that is a component of the file path
basename
(PHP 4, PHP 5)
basename - returns the components of the file path
Description
String basename (String $path[, string $suffix])
Given a string containing the path to the file, this function will return the base archive name.
Parameters
Path
A path.
In Windows, both slash ( / ) and backslash ( ) serve as directory separators. In other environments, it is a forward slash ( / ).
Suffix
If the file name ends with a suffix, it will also be cut off.
Return Value
Returns the path specified by the base name.
Modify
Version Notes
The suffix parameter of 4.1.0 is added
Example
For example # 1 basename ( ) example
$path = "/home/httpd/html/index.php" ;
$file = basename($path); // $file is set to "index.php"
$file = basename($path, ".php"); // $file is set to "index"
? >
The above is the content of the php basename function. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!