Readdir()

I used the script from the PHP manual:

if ($handle = opendir('/wamp/www/stk/lams')) {
while (false !== ($file = readdir($handle))) {
echo "$file\
";
}
}

It produced this output:
. … fileListing.txt LAMS-DR61039-110609-120609-80.99-72.89-52.64-2-PNG.png LAMS-DR6313-110609-110606-39.90-35.91-25.94-1-JPG.jpg LAMS-HE08074-110609-120609-69.99-62.99-45.49-3-JPG.jpg LAMS-IT0740-110609-120609-72.00-64.80-46.80-4-JPG.jpg LAMS-IT0756-110609-120609-119.00-107.10-77.35-5-JPG.jpg LAMS-IT2501-110609-120609-85.00-76.50-55.25-6-JPG.jpg LAMS-IT3843-110609-120609-84.00-75.60-54.60-7-JPG.jpg LAMS-MH12105-110609-120609-169.00-152.10-109.85-8-JPG.jpg LAMS-MW01300-110609-120609-79.99-71.99-51.99-9-JPG.jpg LAMS-POL821-110609-120609-22.99-22.20.69-14.94-10-JPG.jpg LAMS-RG7464-110609-120609-101.00-90.90-85.65-11-JPG.jpg LAMS-RM1507-110609-120609-24.95-22.46-16.22-12-JPG.jpg

Where is the “. …” coming from at the beginning of the output?

How do I suppress it?

Or, do I have to work around it?

Should just avoid opendir unless you have no other means.

SPL offers means but I still like glob.


foreach ( glob( '/wamp/www/stk/lams/*' ) as $file )
  print "$file\
";

if you looked on the manual page for readdir it gives a second example:
Example #2 List all files in the current directory and strip out . and …


if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\
";
        }
    }
    closedir($handle);
}