[英]How do i remove the dots in a php directory
我有一個在目錄中顯示點的代碼。 我正在嘗試擺脫它們,但Google卻無濟於事,這些點表示返回和localhost,需要刪除這些點,我該怎么做?
<?php
$map = opendir('file');
while ($bestand = readdir($map))
{
echo "<a href='file/$bestand'>$bestand</a><br/>";
}
closedir($map);
?>
加
if ($bestand == '.' || $bestand == '..')
continue;
在行包含回聲之前
只要$ bestand是點,此代碼將跳過迭代。
加
if(is_dir($bestand)){ continue; }
在循環。 這將跳過所有目錄,僅添加文件。
參考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.