note 74908 added to function.realpath
| From: | MarcNoirot at osu1 dot php dot net | Date: | Thu, 03 May 2007 15:31:07 +0000 |
| Subject: | note 74908 added to function.realpath | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-126148@lists.php.net to get a copy of this message | ||
Yet another realpath replacement:
function myRealPath($path) {
// Check if path begins with "/". => use === with strpos
if (strpos($path,"/") === 0) {
$path = $_SERVER['DOCUMENT_ROOT'].$path;
}
else {
// Strip slashes and convert to arrays.
$currentDir = preg_split("/\//",dirname($_SERVER['PATH_TRANSLATED']));
$newDir = preg_split('/\//',$path);
// Drop one directory from the array for each ".."; add one otherwise.
foreach ($newDir as $dir) {
if ($dir == "..")
array_pop($currentDir);
elseif ($dir != ".") //test for "." which represents current dir (do
nothing in that case)
array_push($currentDir,$dir);
}
// Return the slashes.
$path = implode($currentDir,"/");
}
return $path;
}
----
Server IP: 217.174.196.197
Probable Submitter: 86.212.110.31
----
Manual Page -- http://www.php.net/manual/en/function.realpath.php
Edit -- https://master.php.net/note/edit/74908
Del: integrated -- https://master.php.net/note/delete/74908/integrated
Del: useless -- https://master.php.net/note/delete/74908/useless
Del: bad code -- https://master.php.net/note/delete/74908/bad+code
Del: spam -- https://master.php.net/note/delete/74908/spam
Del: non-english -- https://master.php.net/note/delete/74908/non-english
Del: in docs -- https://master.php.net/note/delete/74908/in+docs
Del: other reasons-- https://master.php.net/note/delete/74908
Reject -- https://master.php.net/note/reject/74908
Search -- https://master.php.net/manage/user-notes.php