我想请教一下各位会 php 的大大 /大佬们,小弟想利用 php scandir 的功能,在网页上显示某个资料夹的所有文件,但不知如何才可以仅在 output 时把文件的某个字词 删去,例如把以下"sample"删去。
$file"; $i++; } } closedir($dh); ?>
output :
Sample-Apply.png
Sample-Banana.png
Sample-Cherry.png

我想请教一下各位会 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 Feb 3, 2020 via iPhone 字符串查找 |
5 garlics Feb 3, 2020 ``` <?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); ?> |