Forum Moderators: coopster
I'd like to grab the last directory in a file path. For example:
mysite.com/category/sub-category/sub-sub/
I'd like the function to grab the /sub-sub/ part.
Right now I'm using:
$dir = dirname(dirname(__FILE__));
But that returns:
/category/sub-category/
How can I get it to return "sub-sub"?
function getDirectory($path) {
$path = trim($path, '/');
return substr($path, strrpos($path, '/')+1);
}
You are going to have to change this function around a little bit if the path can use either front of back slashes, which depends on your OS.
Hope this helps.