note 76646 added to function.realpath
| From: | berglov1 at hotmail dot com | Date: | Tue, 24 Jul 2007 14:22:16 +0000 |
| Subject: | note 76646 added to function.realpath | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128885@lists.php.net to get a copy of this message | ||
There might be other solutions like mine in here,
but here is one more.
This function converts Virtual Paths into Relative Paths.
I needed that at one time, and I did'nt have much luck finding a solution amongst the PHP
Functions in the manual.
<?php
function GetPath($RedPath) {
if(substr($RedPath, 0, 1) == "/") {
$SysPath = dirname($_SERVER['PHP_SELF']);
if(substr($RedPath, -1) == "/") $RedPath = substr($RedPath, 0, -1);
if(strlen($SysPath) == 1)
return ".".$RedPath;
elseif(strcmp($SysPath,$RedPath) == 0)
return "./";
else {
$s_tmp = split("/", $SysPath);
$r_tmp = split("/", $RedPath);
while(($r_tmp[$i] == $s_tmp[$i]) && $i < 10)
$i++;
$t_RedPath = end(split("/", $RedPath, ($i+1)));
if($i == count($s_tmp))
return "./".$t_RedPath;
else
return str_repeat("../", count($s_tmp)-$i).$t_RedPath;
}
}
else
return $RedPath;
}
?>
----
Server IP: 86.58.145.50
Probable Submitter: 195.215.222.186
----
Manual Page -- http://www.php.net/manual/en/function.realpath.php
Edit -- https://master.php.net/note/edit/76646
Del: integrated -- https://master.php.net/note/delete/76646/integrated
Del: useless -- https://master.php.net/note/delete/76646/useless
Del: bad code -- https://master.php.net/note/delete/76646/bad+code
Del: spam -- https://master.php.net/note/delete/76646/spam
Del: non-english -- https://master.php.net/note/delete/76646/non-english
Del: in docs -- https://master.php.net/note/delete/76646/in+docs
Del: other reasons-- https://master.php.net/note/delete/76646
Reject -- https://master.php.net/note/reject/76646
Search -- https://master.php.net/manage/user-notes.php