Including a whole directory in PHP or Wildcard for use in PHP Include?

后端 未结 5 635
粉色の甜心
粉色の甜心 2021-01-12 07:30

I have a command interpreter in php. It lives inside the commands directory and needs access to every command in the command file. Currently I call require once on each co

5条回答
  •  佛祖请我去吃肉
    2021-01-12 07:56

    You can't require_once a wildcard, but you can programmatically find all the files in that directory and then require them in a loop

    foreach (glob("*.php") as $filename) {
        require_once($filename) ;
    }
    

    http://php.net/glob

提交回复
热议问题