note 105876 added to function.realpath
| From: | imagiro at osu1 dot php dot net | Date: | Wed, 21 Sep 2011 21:20:40 +0000 |
| Subject: | note 105876 added to function.realpath | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-183342@lists.php.net to get a copy of this message | ||
Here is a small and handy method to calculate the relative path from $from to $to. Note: On Windows
it does not work when $from and $to are on different drives.
<?php
function relativePath($from, $to, $ps = DIRECTORY_SEPARATOR)
{
$arFrom = explode($ps, rtrim($from, $ps));
$arTo = explode($ps, rtrim($to, $ps));
while(count($arFrom) && count($arTo) && ($arFrom[0] == $arTo[0]))
{
array_shift($arFrom);
array_shift($arTo);
}
return str_pad("", count($arFrom) * 3, '..'.$ps).implode($ps, $arTo);
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 85.70.197.210
----
Manual Page -- http://www.php.net/manual/en/function.realpath.php
Edit -- https://master.php.net/note/edit/105876
Del: integrated -- https://master.php.net/note/delete/105876/integrated
Del: useless -- https://master.php.net/note/delete/105876/useless
Del: bad code -- https://master.php.net/note/delete/105876/bad+code
Del: spam -- https://master.php.net/note/delete/105876/spam
Del: non-english -- https://master.php.net/note/delete/105876/non-english
Del: in docs -- https://master.php.net/note/delete/105876/in+docs
Del: other reasons-- https://master.php.net/note/delete/105876
Reject -- https://master.php.net/note/reject/105876
Search -- https://master.php.net/manage/user-notes.php