Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

readdir

Description

The readdir of Directory for PHP reads an entry from a directory handle.

Syntax

readdir(
    ?resource $dir_handle = null
): string|false

Parameters

dir_handle

The directory handle resource previously opened with opendir(). If the directory handle is not specified, the last link opened by opendir() is assumed.

Return

Returns the entry name on success or false on failure. WarningThis function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

Examples

1 · void

<?

$directory = ".";

if(opendir($directory))
{
    while(($return = readdir()) !== false)
    {
        echo "$return\n";
    }
    closedir();
}

?>
index.php
my.sock
..
.
127.0.0.1

2 · dir_handle

<?

$directory = ".";

if($dir_handle = opendir($directory))
{
    while(($return = readdir($dir_handle)) !== false)
    {
        echo "$return\n";
    }
    closedir($dir_handle);
}

?>
index.php
my.sock
..
.
127.0.0.1

3 · . ..

<?

$directory = ".";

if(opendir($directory))
{
    while(($return = readdir()) !== false)
    {
        if(($return != ".") && ($return != ".."))
        {
            echo "$return\n";
        }
    }
    closedir();
}

?>
index.php
my.sock
127.0.0.1
HomeMenu