note 19516 added to function.include
| From: | b_AT_bombusbee_DOT_com at php2 dot chek dot com | Date: | Fri, 01 Mar 2002 15:35:00 +0000 |
| Subject: | note 19516 added to function.include | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27230@lists.php.net to get a copy of this message | ||
I built a custom function to accomodate for relative includes from within nested includes (the old a
includes b includes c problem mentioned a couple times above). Use this in place of PHP's
include() function every time, and you can always include a file relative to the current file you
are in. Ex: myInclude("deep/nested/include/file.php")
<?php
function myInclude($fileName)
{
//you are here
$rootPath = getcwd()."/";
//find where we need to go
$aryFilePath = split("/", $fileName);
$fileToInclude = array_pop($aryFilePath);
$includePath = join("/", $aryFilePath) . "/";
//do the include
chdir($rootPath.$includePath);
include($fileToInclude);
chdir($rootPath);
}
?>
Hope this helps someone...
--
http://www.php.net/manual/en/function.include.php
http://master.php.net/manage/user-notes.php?action=edit+19516
http://master.php.net/manage/user-notes.php?action=delete+19516
http://master.php.net/manage/user-notes.php?action=reject+19516