The basename() function is used to extract the filename from a path. In other words, the function returns the filename from a path. It contains two parameters:
- path(Required): it specify the path to check
- suffix(Optional): It is a optional parameter which specify a file extension. If the filename has this extension then it display the filename without extension.
For example:
<?php
$path = "/var/www/demo.php";
//it will display filename with file extension
echo basename($path) ."<br/>";
//it will display filename without file extension
echo basename($path,".php");
?>
The output of the above script will be as follows:
demo.php
demo
0 Comment(s)