PHP basename()Functions
Complete PHP Filesystem Reference Manual
Definition and Usage
The basename() function returns the filename part of a path.
Syntax
basename(path,suffix)
| Parameters | Description |
|---|---|
| path | Required. Specifies the path to be checked. |
| suffix | Optional. Specifies the file extension. If the file has a file extension, this extension will not be displayed. |
Examples
<?php
$path = "/testweb/home.php";
//Show filename with file extension
echo basename($path) ."<br/>";
//Show filename without file extension
echo basename($path,".php");
?>
$path = "/testweb/home.php";
//Show filename with file extension
echo basename($path) ."<br/>";
//Show filename without file extension
echo basename($path,".php");
?>
The code above will output:
home.php
home
home
Complete PHP Filesystem Reference Manual Other Extensions