Re: Parsing back directories to DOCUMENT_ROOT?
| From: | Ryan Adams | Date: | Mon, 05 Jun 2000 17:34:24 +0000 |
| Subject: | Re: Parsing back directories to DOCUMENT_ROOT? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-1066@lists.php.net to get a copy of this message | ||
not elegant, but it might work with your code...
function fix_path ($p) {
$p = ereg_replace ("//", "/", $p);
$a_path = explode ("/", $p);
$n = count($a_path);
for ($i=0; $i<$n; $i++) {
if ($a_path[$i] == "..") {
unset ($a_path[$i]);
if (isset ($a_path[$i-1]))
unset ($a_path[$i-1]);
else {
$j = $i-2;
while (!isset ($a_path[$j])) {
$j--;
} // while
unset ($a_path[$j]);
} // else
} // if
}
return implode ("/", $a_path);
}
On Sun, Jun 04, 2000 at 04:51:55AM -0700, The Doctor What wrote:
> Does anyone have a nice snippet of code to parse back up a directory
> tree (like doing a 'cd ..; pwd' but without changing directory)?
>
> I have a function that generates a sort of backtrace up a directory
> tree:
> Home -> Software -> PHP -> My PHP Example
>
> It would generate this automagically. I have code that works, but
> the URLs it generates are hideous:
> /software/php/../../ for home, as an example.
>
> I'm using explode, which presents other problems, like multiple
> '/'s causing it to act weird.
>
> I figured *someone* must have done something like this.
>
> Thanks.
>
> Ciao!
>
> --
> It has just been discovered that research causes cancer in rats.
>
> The Doctor What: A Holtje Production http://docwhat.gerf.org/
>
> docwhat@gerf.org KF6VNC
---end quoted text---