PHP | DirectoryIterator getBasename()函数
DirectoryIterator::getBasename()函数是PHP中的一个内置函数,用于获取当前 DirectoryIterator 项的基本名称。
句法:
string DirectoryIterator::getBasename( string $suffix )
参数:此函数接受单个参数 $suffix,其中包含以后缀结尾的基本名称。
返回值:此函数返回当前 DirectoryIterator 项的基本名称。
下面的程序说明了PHP中的 DirectoryIterator::getBasename()函数:
方案一:
valid()) {
// Display the base name
echo $directory->getBasename() . "
";
// Move to the next element
$directory->next();
}
?>
输出:
.
..
applications.html
bitnami.css
dashboard
favicon.ico
geeks.PNG
gfg.php
img
index.php
webalizer
xampp
方案二:
key() . " => " .
$dir->getBasename() . "
";
}
?>
输出:
0 => .
1 => ..
2 => applications.html
3 => bitnami.css
4 => dashboard
5 => favicon.ico
6 => geeks.PNG
7 => gfg.php
8 => img
9 => index.php
10 => webalizer
11 => xampp
注意:此函数的输出取决于服务器文件夹的内容。
参考: https://www. PHP.net/manual/en/directoryiterator.getbasename。 PHP