Retrieve the filename from a given path.
<?php $path = “/testweb/home.php”; //Show filename echo basename($path) .“<br/>”; //Show filename, but cut off file extension for “.php” files echo basename($path,“.php”); ?> |
The result of the code above will be:
home.php home |
The basename() function extracts the filename from a given path.
basename(path, suffix) |
Parameter |
Description |
path |
Mandatory. Specifies the path to the file. |
suffix |
Optional. A file extension. If the filename includes this extension, it will be removed from the result. |
Return Value: |
The name of the file in the given path. |
PHP Version: |
4.0+ |