Home > Article > Backend Development > php basename function_PHP tutorial
Let's take a look at the tutorial that provides an example of the basename function, which is a component of the file path.
Let’s take a look at the components that provide a file pathbasenamefunction example tutorial
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 file name.
Parameters
Path
a path.
In Windows, both slash ( / ) and backslash ( ) serve as directory separators. In other environments, it is a forward slash ( / ).
Suffix
The file name will also be cut off if it ends with a suffix.
Return value
Returns the path specified by the base name.
Modify
Release Notes
The suffix parameters of 4.1.0 are increased
Example
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"
?>