The basename() function gets the the filename component of a path. The file path is set as a parameter.
file_path − Set the path of file or directory to be checked. Required.
suffix − Set the extension of the file. Optional.
The basename() function returns the basename of the file.
The following is an example that checks for file “new.php” and returns the basename with the extension since we added the suffix parameter.
<?php $file_path = "/backup/myfiles/new.php"; // displays name of the file with extension echo basename($file_path); ?>
Let us see another example that checks the file and display the basename without the extension.
<?php $file_path = "/backup/myfiles/new.php"; // displays name of the file without extension echo basename($file_path,".php"); ?>