note 76646 deleted from function.realpath by peehaa
| From: | peehaa@php.net | Date: | Sun, 28 Apr 2019 09:47:31 +0000 |
| Subject: | note 76646 deleted from function.realpath by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210704@lists.php.net to get a copy of this message | ||
Note Submitter: berglov1 at hotmail dot com
----
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;
}
?>