[UPHPU] simple??? php function (display an index)

Alvaro Carrasco alvaro at epliant.com
Wed Jul 19 12:43:57 MDT 2006


Saint Chaos wrote:
> On 7/19/06, Lonnie Olson <fungus at aros.net> wrote:
>
>> A better way to write the function would be:
>> <?php
>> function directory($directory='.') {
>>      print "<ul>\n";
>>      $handle = opendir($directory);
>>      while ($file = readdir($handle)) {
>>          if ($file != '.' && $file != '..') {
>>              print "<li><a href=\"$directory/$file\">$file</a></li>\n";
>>          }
>>      }
>>      closedir($handle);
>>      print "</ul>";
>> }
>> ?>
>>
>> This function uses a list for markup (easier to style), and allows
>> you to pass in a directory name.
>>
>> --lonnie
>>
>>
>>
>>
> That is a much nicer way to do it. I just through the other as a quick
> example of how to do it, didn't really look to deeply into what it 
> did. :)
If you're using php5 you might want to try the DirectoryIterator class:
http://us2.php.net/manual/en/function.directoryiterator-construct.php


More information about the UPHPU mailing list