1 回答

TA貢獻1842條經驗 獲得超13個贊
PHPinclude不應用于其他文件類型,例如.json. 要從這些文件中提取數據,您需要使用類似file_get_contents. 例如:
$data = json_decode(file_get_contents('someFile3.json'));
要遞歸地將 PHP 文件包含在其他目錄中,您可以嘗試遞歸搜索所有目錄:
function require_all($dir, $max_scan_depth, $depth=0) {
if ($depth > $max_scan_depth) {
return;
}
// require all php files
$scan = glob("$dir/*");
foreach ($scan as $path) {
if (preg_match('/\.php$/', $path)) {
require_once $path;
}
elseif (is_dir($path)) {
require_all($path, $max_scan_depth, $depth+1);
}
}
}
$max_depth = 255;
require_all('folder3', $max_depth);
此代碼是此處代碼的修改版本:https ://gist.github.com/pwenzel/3438784
- 1 回答
- 0 關注
- 135 瀏覽
添加回答
舉報