首页 > 解决方案 > 获取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 中

标签: php

解决方案


你可以使用

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


推荐阅读