Require multiple files

后端 未结 3 668
别跟我提以往
别跟我提以往 2021-01-02 10:20

I am building a PHP application that uses a select menu to build email templates. The templates are broken into reusable parts (each is a separate html file). Is there an

3条回答
  •  甜味超标
    2021-01-02 10:44

    EDIT:

    Because you want to require or include multiple files, you could use this recursive algorithm to include files in a specified folder. The folder is the root that starts the iterator. Because the algorithm is recursive, it will automatically traverse all subsequent folders and include those files as well.

    public function include_all_files($root) {
        $d = new RecursiveDirectoryIterator($root);
        foreach (new RecursiveIteratorIterator($d) as $file => $f) {
            $ext = pathinfo($f, PATHINFO_EXTENSION);
            if ($ext == 'php' || $ext == 'inc')
                include_once ($file); // or require(), require_once(), include_once()
        }
    }
    
    include_all_files('./lib');
    

提交回复
热议问题