當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP DirectoryIterator isDot()用法及代碼示例


DirectoryIterator::isDot()函數是PHP中的內置函數,用於檢查當前DirectoryIterator項是“。”還是“ ..”

用法:

bool DirectoryIterator::isDot( void )

參數:該函數不接受任何參數。


返回值:如果輸入為,則此函數返回TRUE。或..,否則為FALSE。

以下示例程序旨在說明PHP中的DirectoryIterator::isDot()函數:

示例1:

<?php 
  
// Create a directory Iterator 
$directory = new DirectoryIterator(dirname(__FILE__)); 
  
// Loop runs for each element of directory 
foreach($directory as $dir) { 
      
    // Check if not a dot directory 
    if (!$dir->isDot()) { 
  
        // Display directory element and its permission 
        $perms = substr(sprintf('%o', $dir->getPerms()), -4); 
        echo $dir->getFilename() . " " 
        . " | Permission: " . $perms . "<br>"; 
    } 
} 
  
?>

輸出:

applications.html | Permission: 0666
bitnami.css | Permission: 0666
dashboard | Permission: 0777
favicon.ico | Permission: 0666
geeks.PNG | Permission: 0666
gfg.php | Permission: 0666
img | Permission: 0777
index.php | Permission: 0666
Sublime Text Build 3211 x64 Setup.exe | Permission: 0777
webalizer | Permission: 0777
xampp | Permission: 0777

示例2:

<?php 
  
// Create a directory Iterator 
$directory = new DirectoryIterator(dirname(__FILE__)); 
  
// Loop runs while directory is valid 
while ($directory->valid()) { 
  
    // Check if not a dot directory 
    if (!$directory->isDot()) { 
        echo $directory->getFilename() . "<br>"; 
    } 
    $directory->next(); 
} 
  
?>

輸出:

applications.html
bitnami.css
dashboard
favicon.ico
geeks.PNG
gfg.php
img
index.php
Sublime Text Build 3211 x64 Setup.exe
webalizer
xampp

注意:此函數的輸出取決於服務器文件夾的內容。

參考: https://www.php.net/manual/en/directoryiterator.isdot.php



相關用法


注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | DirectoryIterator isDot() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。