note 46503 deleted from function.realpath by tomsommer
| From: | tomsommer@php.net | Date: | Wed, 13 Oct 2004 16:04:48 +0000 |
| Subject: | note 46503 deleted from function.realpath by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-78500@lists.php.net to get a copy of this message | ||
Note Submitter: jemore at palmeteo pointdot com
----
A recursive function to simplify path : remove '..' from an URL.
<?php
function getRealpathUrl($path)
{
$p = strpos($path, '..');
if ($p !== false)
{
// searh for the first / on the left of ..
$pos_slash = -1;
$i = $p - 2;
while ($i > 0)
{
if ($path[$i] == '/')
{
$pos_slash = $i;
break;
}
$i --;
}
$path = substr($path, 0, $pos_slash).substr($path, $p + 2, strlen($path));
return getRealpathUrl($path);
}
return $path;
}
?>