PHP | SplFileInfo getBasename() Function
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 // PHP Program to illustrate // Splfileinfo::getBasename() function // Create new SPlFileInfo Object $file = new SplFileInfo('html/gfg.txt'); // Print result var_dump($file->getBasename()); ?> |
string(7) "gfg.txt"
Program 2:
<?php // PHP program to use array to check // multiple files $GFG = array ( "/home/rajvir/Desktop/GeeksforGeeks/dummy.php", "/home/rajvir/Desktop/gfg.txt", "/var/www/html/gfg.php", "demo.php"); foreach ($GFG as &$file) { // Create new SPlFileInfo Object $file = new SplFileInfo($file); // Print result var_dump($file->getBasename()); } ?> |
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
Recommended Posts:
- PHP | SplFileInfo openFile() Function
- PHP | SplFileInfo isReadable() Function
- PHP | SplFileInfo getPerms() Function
- PHP | SplFileInfo isWritable() Function
- PHP | SplFileInfo getATime() Function
- PHP | SplFileInfo isLink() Function
- PHP | SplFileInfo isDir() Function
- PHP | SplFileInfo getSize( ) Function
- PHP | SplFileInfo getType() Function
- PHP | SplFileInfo isExecutable() Function
- PHP | SplFileInfo isFile() Function
- PHP | SplFileInfo getRealPath() Function
- PHP | SplFileInfo getInode() Function
- PHP | SplFileInfo getMTime() Function
- PHP | SplFileInfo getOwner() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



