Tom*_*igh 49
可能只做这样的事情:
$files = glob($dir . '/*.php');
foreach ($files as $file) {
require($file);
}
Run Code Online (Sandbox Code Playgroud)
这可能是使用更高效opendir()和readdir()比glob().
sou*_*rge 23
没有简短的方法,你需要在PHP中实现它.这样的事情应该足够了:
foreach (scandir(dirname(__FILE__)) as $filename) {
$path = dirname(__FILE__) . '/' . $filename;
if (is_file($path)) {
require $path;
}
}
Run Code Online (Sandbox Code Playgroud)
K. *_*ert 12
没有简单的方法,就像在Apache中一样,只需要Include /path/to/dir包含所有文件.
一种可能的方法是使用SPL中的RecursiveDirectoryIterator:
function includeDir($path) {
$dir = new RecursiveDirectoryIterator($path);
$iterator = new RecursiveIteratorIterator($dir);
foreach ($iterator as $file) {
$fname = $file->getFilename();
if (preg_match('%\.php$%', $fname)) {
include($file->getPathname());
}
}
}
Run Code Online (Sandbox Code Playgroud)
无论它们在结构中有多深,这都将从中拉出所有.php结束文件$path.
简单:
foreach(glob("path/to/my/dir/*.php") as $file){
require $file;
}
Run Code Online (Sandbox Code Playgroud)
foreach循环。foreach (glob("classes/*") as $filename) {
require $filename;
}
Run Code Online (Sandbox Code Playgroud)
有关更多详细信息,请查看之前发布的问题:
| 归档时间: |
|
| 查看次数: |
39405 次 |
| 最近记录: |