我想请教一下各位会 php 的大大 /大佬们,小弟想利用 php scandir 的功能,在网页上显示某个资料夹的所有文件,但不知如何才可以仅在 output 时把文件的某个字词 删去,例如把以下"sample"删去。
$fileoutput :
Sample-Apply.png
Sample-Banana.png
Sample-Cherry.png
1
wen0750 OP <?php
$path = "."; $dh = opendir($path); $i=1; while (($file = readdir($dh)) !== false) { if($file !="filelist.php" && $file != "." && $file != ".." && $file != "index.php" && $file != ".htaccess" && $file != "error_log" && $file != "cgi-bin") { echo "<a href='$path/$file'>$file</a><br /><br />"; $i++; } } closedir($dh); ?> |
2
jugelizi 2020-02-03 10:47:09 +08:00 via iPhone
字符串查找
|
5
garlics 2020-02-03 13:50:30 +08:00 1
```
<?php $path = "."; $dh = opendir($path); $i=1; while (($file = readdir($dh)) !== false) { if($file !="filelist.php" && $file != "." && $file != ".." && $file != "index.php" && $file != ".htaccess" && $file != "error_log" && $file != "cgi-bin") { $file = str_replace("Sample-","",$file); echo "<a href='$path/$file'>$file</a><br /><br />"; $i++; } } closedir($dh); ?> ``` |
7
wen0750 OP <?php
$path = "."; $dh = opendir($path); $i=1; while (($file = readdir($dh)) !== false) { if($file !="filelist.php" && $file != "." && $file != ".." && $file != "index.php" && $file != ".htaccess" && $file != "error_log" && $file != "cgi-bin") { $name = str_replace("Sample-","",$file); echo "<a href='$path/$file'>$name</a><br /><br />"; $i++; } } closedir($dh); ?> |