php - 获取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 中
解决方案
你可以使用
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);
?>
推荐阅读
- javascript - 在 JavaScript 中绑定 onclick 而无需在 HTML 文件中直接使用 JS
- sql - 如何在 iOS 应用程序和 Django WebApp 之间进行数据通信
- c# - 通过 autofac 模拟后,服务的实际实现被调用
- bash - 排序,考虑到后缀数字
- c# - 用一根手指按下时尝试检测按钮按下时出现问题 - Unity
- python - 如何在不使用 numpy.linspace() 的情况下在 Python 中创建线性函数
- c# - 覆盖 EF Core 的 Guid 生成
- javascript - 单击按钮时未显示结果 - HTML、JavaScript
- java - 如何实时远程调试更改
- prolog - Prolog 中的“循环”,用 `fail` 替换目标