DirectoryIterator::getBasename()函數是PHP中的內置函數,用於獲取當前DirectoryIterator項的基本名稱。
用法:
string DirectoryIterator::getBasename( string $suffix )
參數:此函數接受單個參數$suffix,該參數保存基本名稱以後綴結尾。
返回值:此函數返回當前DirectoryIterator項的基本名稱。
以下示例程序旨在說明PHP中的DirectoryIterator::getBasename()函數:
程序1:
<?php
// Create a directory Iterator
$directory = new DirectoryIterator(dirname(__FILE__));
// Loop runs while directory is valid
while ($directory->valid()) {
// Display the base name
echo $directory->getBasename() . "<br>";
// Move to the next element
$directory->next();
}
?>
輸出:
. .. applications.html bitnami.css dashboard favicon.ico geeks.PNG gfg.php img index.php webalizer xampp
程序2:
<?php
// Create a directory Iterator
$directory = new DirectoryIterator(dirname(__FILE__));
// Loop runs for each element of directory
foreach($directory as $dir) {
// Display the key and basename
echo $dir->key() . " => " .
$dir->getBasename() . "<br>";
}
?>
輸出:
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
相關用法
- PHP SplFileInfo getBasename()用法及代碼示例
- PHP DirectoryIterator next()用法及代碼示例
- PHP DirectoryIterator key()用法及代碼示例
- PHP DirectoryIterator getCTime()用法及代碼示例
- PHP DirectoryIterator __construct()用法及代碼示例
- PHP DirectoryIterator current()用法及代碼示例
- PHP DirectoryIterator isWritable()用法及代碼示例
- PHP DirectoryIterator isDir()用法及代碼示例
- PHP DirectoryIterator isLink()用法及代碼示例
- PHP DirectoryIterator isReadable()用法及代碼示例
- PHP DirectoryIterator isFile()用法及代碼示例
- PHP DirectoryIterator getPerms()用法及代碼示例
- PHP DirectoryIterator isExecutable()用法及代碼示例
- PHP DirectoryIterator getATime()用法及代碼示例
- PHP DirectoryIterator valid()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | DirectoryIterator getBasename() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。