dir in PHP

Syntax of dir in PHP

directory dir(string path[, resource context])

Returns an instance of the directory class initialized to the given path. You can use the read(), rewind(), and close() methods on the object as equivalent to the readdir(), rewinddir(), and closedir() procedural functions.

Example of dir in PHP

<?php
$d = dir("/etc/php5");
echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";
while (false !== ($entry = $d->read())) {
   echo $entry."\n";
}
$d->close();
?>

Output of dir

Handle: Resource id #2
Path: /etc/php5
.
..
apache
cgi
cli

Leave a Comment