简体   繁体   中英

How do i remove the dots in a php directory

I have a code that shows dots in the directory. I'm trying to get rid of them but google doesn't help, those dots mean back and localhost and the dots need to be removed how do i do this?

<?php
 $map = opendir('file');
 while ($bestand = readdir($map))
 {
   echo "<a href='file/$bestand'>$bestand</a><br/>"; 
 }
 closedir($map); 
?>

those dots

add

if ($bestand == '.' || $bestand == '..')
    continue;

before the line contains echo

This code will skip iteration whenever $bestand is the dots.

add

if(is_dir($bestand)){ continue; }

in the loop. This will skip all directories and only add files.

Referring to the manual at php.net and adding to HungHsuan Wei's answer.

<?php

if ($map = opendir('file')) {

    /* This is the correct way to loop over the directory. */
    while (false !== ($entry = readdir($map))) {
        if($bestand == '.' || $bestand == '..')
        continue;
    }    
    closedir($handle);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM