(PHP 4, PHP 5, PHP 7)
readdir — Read entry from directory handle
$dir_handle
] )Returns the name of the next entry in the directory. The entries are returned in the order in which they are stored by the filesystem.
Returns the entry name on success sau FALSE
în cazul eșecului.
Această funcție poate întoarce valoarea Boolean FALSE
, dar poate de
asemenea întoarce o valoare non-Boolean care evaluează în FALSE
. Vă rugăm să
citiți secțiunea despre tipul Boolean
pentru informații suplimentare. Utilizați
operatorul === pentru a
verifica valoarea întoarsă de această funcție.
Example #1 List all entries in a directory
Please note the fashion in which readdir()'s
return value is checked in the examples below. We are explicitly
testing whether the return value is identical to (equal to and of
the same type as--see Comparison
Operators for more information) FALSE
since otherwise,
any directory entry whose name evaluates to FALSE
will stop the
loop (e.g. a directory named "0").
<?php
if ($handle = opendir('/path/to/files')) {
echo "Directory handle: $handle\n";
echo "Entries:\n";
/* This is the correct way to loop over the directory. */
while (false !== ($entry = readdir($handle))) {
echo "$entry\n";
}
/* This is the WRONG way to loop over the directory. */
while ($entry = readdir($handle)) {
echo "$entry\n";
}
closedir($handle);
}
?>
Example #2 List all entries in the current directory and strip out . and ..
<?php
if ($handle = opendir('.')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
echo "$entry\n";
}
}
closedir($handle);
}
?>