我想從沒有任何數據庫的目錄讀取html文件名。我有一個代碼,它的工作正常,但它給出了兩個空白名稱,而我在目錄中只有4個文件。從目錄中讀取文件名
<?php
if (is_dir('dir')) {
if ($dh = opendir('dir')) {
while (($file = readdir($dh)) !== false) {
echo "filename:".$file."<br />";
}
}
}?>
我有4個HTML文件和輸出應該是:
filename:aaaaaa kjnnk_13.html
filename:aaaaaa kjnnk_2.html
filename:aaaaaa kjnnk_6.html
filename:aaaaaa kjnnk_9.html
但我發現2個額外的文件名:
filename:.
filename:..
filename:aaaaaa kjnnk_13.html
filename:aaaaaa kjnnk_2.html
filename:aaaaaa kjnnk_6.html
filename:aaaaaa kjnnk_9.html
請幫
'if($ file!='。'&& $ file!='..')' –
hank you for reply ...但是在哪裏添加條件? – user3526766
也許在'echo'之前? –