Michael Nagler: Reihenfolge bei readdir()

Beitrag lesen

Hallo,

Meine PHP-Referenz sagt mir: "readdir()" gibt den Inhalt des Verzeichnisses unsortiert aus.

Das PHP Manual sagt dazu folgendes:

Returns the filename of the next file from the directory. The filenames are returned in the order in which they are stored by the filesystem.

Wenn die Sortierung so wichtig ist, mach es doch einfach selbst:

<?php
// Ab PHP V4.0.0-RC2
$files = array();
if( $handle = opendir('/path/to/files'))
{

while (false !== ($file = readdir($handle))) {
       $files[] = $file;
   }
   closedir($handle);

// sortieren:
   $files = sort( $files );
   reset( $files );
}
?>

Viele Grüße,
Michael

--

<img src="http://www.nailware.de/images/nailware_logo.jpg" border="0" alt="">
--
<img src="http://www.nailware.de/images/no_epatents.gif" border="0" alt="">
Online Petitionen gegen Software Patente:
http://petition.eurolinux.org/index_html?LANG=de