PHP 按名称包含

发布于 2024-08-28 11:34:22 字数 316 浏览 2 评论 0原文

我有一个 content 文件夹,其中充满了按以下方式命名的其他子目录:

id1_1
id1_2
id1_3
id2_1
id2_2

等等。每个文件夹都包含一个文件 template.php

文件夹的数量是动态的,因此我需要找到一种方法将从所有以 id_1_ 开头的文件夹中导入所有 template.php 到我的 index.php< /代码> 文件。有什么简单的方法可以做到这一点吗?

I have a content folder which is full of other sub-directories named in the following way:

id1_1
id1_2
id1_3
id2_1
id2_2

And so on. Each of these folders contains a file template.php.

The number of folders is dynamic, so I need to find a way to import all the template.php from all folders starting with id_1_ into my index.php file. Is there any easy way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤独陪着我 2024-09-04 11:34:22

您可以使用 glob() 函数:

$arrFiles = glob('./id_1_*/template.php');
foreach($arrFiles as $file) {
     include_once($file);
}

You can use the glob() function:

$arrFiles = glob('./id_1_*/template.php');
foreach($arrFiles as $file) {
     include_once($file);
}
橘寄 2024-09-04 11:34:22

可以使用递归函数+foreach+glob:

http://www.php.net/glob

You can use a recursive function + foreach + glob:

http://www.php.net/glob

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文