Re: get last directory of a full path? (parent directory)
| From: | Romulo Roberto Pereira | Date: | Sun, 21 Jan 2001 00:05:00 +0000 |
| Subject: | Re: get last directory of a full path? (parent directory) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-35858@lists.php.net to get a copy of this message | ||
Hello!
> whats the easiest way to go from "/dir1/dir2/dir3/hello.php" to "dir3/" ?
> dirname will cut off hello.php but i want to cut dir1 and dir2 as well
<?php
$dir_path = "/dir1/dir2/dir3/hello.php";
$dirs = explode("/",$dir_path);
$numberofelements = count($dirs);
$i = 1;
foreach ($dirs as $value) {
if ($i == ($numberofelements-1)) $lastdir = $value;
if ($i == $numberofelements) $file = $value;
$i++;
}
echo $lastdir."/".$file;
?>
I believe that this will do the job