[PHP] get last directory of a full path? (parent directory)

2001-01-20 Thread Noah Spitzer-Williams

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

Thanks!

- Noah



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] get last directory of a full path? (parent directory)

2001-01-20 Thread Stephan Ahonen

 $i = 1;
 foreach ($dirs as $value) {
  if ($i == ($numberofelements-1)) $lastdir = $value;
  if ($i == $numberofelements) $file = $value;
  $i++;
 }

I don't think the foreach is necessary - Why can't you just say:

$lastdir = $dirs[$numberofelements-1];
$file = $dirs[$numberofelements];

That way you're not traversing the entire array, you're just getting what
you need, more efficient. Now if only you could work with files the same way
you can with arrays...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]