The basename()
function is a built-in function in PHP. Given the path of any file, this method can remove the entire path and return only the filename.
string basename ( $path , $suffix )
$path
: String value that specifies the path of a file.
$suffix
: An optional parameter used if a user does not want to return the extension of the file.
This function returns just the name of the file, removing the path.
Here is a coding example of the basename
function.
<?php$path = "user/home/documents/Hello.txt";// using the function on the specified pathecho basename($path);?>
<?php$path = "user/home/documents/Hello.txt";// using suffix parameterecho basename($path, ".txt");?>
Free Resources