dshadow.com
Seven Ways To Make A Directory Listing
Someone on #php on OPN needed a little help in getting a directory listing. So we went a little overboard.

Know another (sufficiently distinct) way? Hit the feedback button below.

With backticks (or system) (philip, JFK)

$lines = explode("\n", `ls`);

$lines = explode("\n", system('ls'));
With exec (DShadow)

exec('ls', $lines):
With output buffering and passthru (DShadow)

ob_start();
passthru('ls');
$lines = explode("\n", ob_get_contents());
ob_end_clean();
With popen (DShadow)

$str = '';
$fd = popen('ls', 'r');
while(!feof($fd))
	$str .= fread($fd, 4096);
fclose($fd);
$lines = explode("\n", $str);
With opendir (\n)

$lines = array();
$dir = opendir('dir');
while($fn = readdir($dir))
	$lines[] = $fn;
closedir($dir);
By cheating (DShadow)

Write a PHP module to do the ls and return an array.
By cheating some more

Parse the web server's directory listing. (\n)
Use the FTP functions to parse an FTP directory listing. (BatmanPPC)

Submissions

Reinvent the wheel (BatmanPPC)

Re-implement ls as a commandline PHP script. Then use this script in place of ls in the above methods.
Shell output redirection (Kimihia)

$name = tempnam('/tmp', 'FOO');
system("ls > $name");
$list = file($name);
unlink($name);
When ls fails... ([RainMkr])
NOTE: won't work if you have files whose names contain spaces.

$lines = explode(' ', `cd /path/to/files; echo *`)
The phpNuke way (MarkL)

exec('ls -la -R /');
With PHP's dir() function/class (MonkeyMan)

$d = dir("/etc");
while (false !== ($entry = $d->read()))
	$list[] = $entry;
$d->close();