因此,假设我们有一个名为“ 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中
答案 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);
?>
处了解更多信息