note 36726 added to function.realpath
| From: | mail at mariocarbonell dot com | Date: | Mon, 20 Oct 2003 13:11:18 +0000 |
| Subject: | note 36726 added to function.realpath | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-58940@lists.php.net to get a copy of this message | ||
After having tested Jose Miguel resolvePath() and seeing that doesn't works perfect, i've
rewrite my own version using regular expresions.
// This funcion performs ereg_replace iteratively until no changes is made.
function iterate_ereg_replace ( $pattern, $replacement, $string) {
$result = $string;
do {
$string = $result;
$result = ereg_replace ($pattern, $replacement, $string);
} while ($result != $string);
return $result;
}
// This funcion performs the translation using regular expresions.
function resolvePath2 ($dest, $orig) {
if ($dest == "") return $orig;
if ($orig == "") return $dest;
if ($dest[0] == "/") return $dest;
if ($orig[0] != "/") $orig = "/".$orig;
if ($orig[strlen($orig)-1] != "/") $orig = dirname($orig)."/";
$path = $orig.$dest;
$path = ereg_replace ("/+", "/", $path);
$path = iterate_ereg_replace ("/\./", "/", $path);
$path = iterate_ereg_replace ("/[^(/|\.)]+/\.\./", "/", $path);
return $path;
}
Mario Carbonell.
http://www.mariocarbonell.com
----
Manual Page -- http://www.php.net/manual/en/function.realpath.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36726
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36726&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36726&report=yes
Search -- http://master.php.net/manage/user-notes.php