The SplFileInfo::getBasename() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to get the base name of the file.
Syntax:
string SplFileInfo::getBasename( $suffix )
Parameters: This function accepts single parameter $suffix which is optional. It is used to specify the base name.
Return Value: This function returns the base name without path information.
Below programs illustrate the SplFileInfo::getBasename() function in PHP:
Program 1:
<?php
$file = new SplFileInfo('html/gfg.txt');
var_dump($file->getBasename());
?>
|
Output:
string(7) "gfg.txt"
Program 2:
<?php
$GFG = array (
"/home/rajvir/Desktop/GeeksforGeeks/dummy.php",
"/home/rajvir/Desktop/gfg.txt",
"/var/www/html/gfg.php",
"demo.php"
);
foreach ($GFG as &$file) {
$file = new SplFileInfo($file);
var_dump($file->getBasename());
}
?>
|
Output:
string(9) "dummy.php"
string(7) "gfg.txt"
string(7) "gfg.php"
string(8) "demo.php"
Reference: http://php.net/manual/en/splfileinfo.getbasename.php
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
17 Dec, 2018
Like Article
Save Article