简体   繁体   English

如何删除php目录中的点

[英]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? 我正在尝试摆脱它们,但Google却无济于事,这些点表示返回和localhost,需要删除这些点,我该怎么做?

<?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. 只要$ bestand是点,此代码将跳过迭代。

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.net上的手册,并添加到HungHsuan Wei的答案中。

<?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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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