note 83872 deleted from function.include by danbrown

From: Date: Mon, 18 May 2009 00:55:36 +0000
Subject: note 83872 deleted from function.include by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155449@lists.php.net to get a copy of this message
Note Submitter: marabbeh ---- Thanks to alex carstea and tim furry for absolute path function. Here is (just) a bit faster version : <?php // The function returns the absolute path to the file to be included. // This path can be used as argument to include() and resolves the problem of nested inclusions. function getFilePath($relative_path) { // $abs_path is the current absolute path (replace "\\" to "/" for windows platforms) $abs_path=str_replace("\\", "/", dirname($_SERVER['SCRIPT_FILENAME'])); $relative_array=explode("/",$relative_path); $abs_array=explode("/",$abs_path); // for each "../" at the beginning of $relative_path // removes this 1st item from $relative_path and the last item from $abs_path while ($relative_array and ($relative_array[0]=="..")) { array_shift($relative_array); array_pop($abs_array); } // and implodes both arrays return implode("/", $abs_array) . "/" . implode("/", $relative_array); } ?>

« previous php.notes (#155449) next »