PHP scandir 上的问题

2020-02-03 02:26:35 +08:00
 wen0750

我想请教一下各位会 php 的大大 /大佬们,小弟想利用 php scandir 的功能,在网页上显示某个资料夹的所有文件,但不知如何才可以仅在 output 时把文件的某个字词 删去,例如把以下"sample"删去。

$file

"; $i++; } } closedir($dh); ?>

output :

Sample-Apply.png

Sample-Banana.png

Sample-Cherry.png

2966 次点击
所在节点    PHP
7 条回复
wen0750
2020-02-03 02:29:01 +08:00
<?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);
?>
jugelizi
2020-02-03 10:47:09 +08:00
字符串查找
wen0750
2020-02-03 13:05:30 +08:00
@jugelizi 想問一下大致上要怎麼做?
wen0750
2020-02-03 13:06:10 +08:00
@jugelizi 想问一下大致上要怎么做?
garlics
2020-02-03 13:50:30 +08:00
```
<?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);
?>
```
wen0750
2020-02-03 19:38:50 +08:00
@garlics 谢谢大哥你的帮忙。
wen0750
2020-02-04 22:52:15 +08:00
<?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);
?>

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/641744

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX