Re: how: Output of 'ls' as an array

From: Date: Thu, 01 Jun 2000 15:40:07 +0000
Subject: Re: how: Output of 'ls' as an array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-824@lists.php.net to get a copy of this message
> How would I save the output of 'ls -l' as an array. I need to be able to > take each line and save it as an entry in an array for use later. Does > anyone know how this can be done? Use exec() and pass in an array as the second parameter. This gets filled with each line being a single item. e.g. <?php $path = "/home/httpd/html"; $out = array(); exec("ls -l $path", $out); echo "<pre>"; for ($i = 0; $i < count($out); $i++) { echo $out[$i] . "\n"; } echo "</pre>"; ?> Andrew

« previous php.general (#824) next »