PHP basename() Function
Definition and Usage
The basename() function returns the filename part of the path.
Syntax
basename(path,suffix)
Parameter | Description |
---|---|
path | Required. Specifies the path to be checked. |
suffix | Optional. Specifies the file extension. If the file has a suffix, this extension will not be output. |
Example
<?php $path = "/testweb/home.php"; //Display the filename with the file extension echo basename($path); //Display the filename without the file extension echo basename($path,".php"); ?>
Output:
home.php home