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
- [PHP] get last directory of a full path? (parent di... Noah Spitzer-Williams
- Re: [PHP] get last directory of a full path? (... Romulo Roberto Pereira
- Re: [PHP] get last directory of a full pat... Stephan Ahonen