获取PHP文件夹中的所有文件名

时间:2018-09-22 18:43:16

标签: php

因此,假设我们有一个名为“ Template”的文件夹,在该文件夹中,我们有

模板-

home.php
about.php
contact.php

现在在index.php文件中,我想将其称为php文件,而不是将每个文件的内容仅称为文件名home about contact。因此index.php的输出应该是这样的:

HELLO WORLD! Here are the list of filenames inside the template folder!
HOME
ABOUT
CONTACT

我在这里检查了其他答案,但是不在PHP中

1 个答案:

答案 0 :(得分:1)

您可以使用

array scandir ( string $directory [, int $sorting_order = SCANDIR_SORT_ASCENDING [, resource $context ]] )

示例:

<?php
$dir    = '/public';
$files1 = scandir($dir);
$files2 = scandir($dir, 1);

print_r($files1);
print_r($files2);
?>

http://php.net/manual/en/function.scandir.php

处了解更多信息