Friday, November 13th, 2009

Always messed around with a combo of opendir(), readdir(), and closedir() if you wanted to read the contents of a directory? Since PHP 5 there is a new sheriff in town: scandir():

<?php
$files=scandir("/etc/php5");
print_r($files);
?>

Outputs:

Array
(
[0] => .
[1] => ..
[2] => apache2
[3] => conf.d
)

Okay, you still need to traverse an array, but it's much easier to use than the traditional way.

Leave a Reply

This blog copyright 2010-2012 by Kai 'Oswald' Seidler