PHP include by name
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 fold开发者_Python百科ers starting with id_1_ into my index.php file. Is there any easy way to do this?
You can use the glob() function:
$arrFiles = glob('./id_1_*/template.php');
foreach($arrFiles as $file) {
include_once($file);
}
You can use a recursive function + foreach + glob:
http://www.php.net/glob
加载中,请稍侯......
精彩评论