note 83872 added to function.include

From: Date: Mon, 16 Jun 2008 13:46:00 +0000
Subject: note 83872 added to function.include
Groups: php.notes 
Request: Send a blank email to php-notes+get-140503@lists.php.net to get a copy of this message
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); } ?> ---- Server IP: 217.160.72.57 Probable Submitter: 82.225.190.16 ---- Manual Page -- http://www.php.net/manual/en/function.include.php Edit -- https://master.php.net/note/edit/83872 Del: integrated -- https://master.php.net/note/delete/83872/integrated Del: useless -- https://master.php.net/note/delete/83872/useless Del: bad code -- https://master.php.net/note/delete/83872/bad+code Del: spam -- https://master.php.net/note/delete/83872/spam Del: non-english -- https://master.php.net/note/delete/83872/non-english Del: in docs -- https://master.php.net/note/delete/83872/in+docs Del: other reasons-- https://master.php.net/note/delete/83872 Reject -- https://master.php.net/note/reject/83872 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140503) next »