note 42896 added to function.include
| From: | cbrumelle at xaia dot ca | Date: | Wed, 02 Jun 2004 22:38:25 +0000 |
| Subject: | note 42896 added to function.include | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-70726@lists.php.net to get a copy of this message | ||
Over the years Ive built up a large library of custom classes and I hate having to
require_once huge numbers of them in a config file. I wrote this simple little function that
imports all the files in a directory.
It helps me
maybe it can help someone else.
<?php
/*----------------------------------------
* Import
*------------------------------------------
* Similiar to Java's import statement...
*
* This function calls 'require_once()' for all files that end
* with '.php' (by default), or end with the string passed in
* the optional second parameter '$ext', in the directory specified
* in '$path'.
*
* Example:
*
* import('lib/Auth', '.inc'); //includes all files in the ./lib/Auth dir that
end with '.inc'
* import('lib/Cart); //includes all files in the ./lib/Cart dir that end with '.php'
*/
function import($path, $ext = '.php'){
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if (substr($file, -(strlen($ext))) == $ext)
require_once($path.'/'.$file);
}
}
closedir($handle);
}
?>
Colin Brumelle
----
Manual Page -- http://www.php.net/manual/en/function.include.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42896
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42896&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42896&report=yes
Search -- http://master.php.net/manage/user-notes.php