How can I get the name of the current directory - not the whole path? [duplicate]
Possible Duplicate:
How to get the last dir fr开发者_JAVA百科om a path in a string
I'm using getcwd()
to return something like this: home/abc123/public_html/blah/myDir
How can I modify this string to simply return myDir
?
http://php.net/manual/en/function.basename.php
Either use basename:
print basename("home/abc123/public_html/blah/myDir");
//Output: myDir
Or strpos
and substr
:
$fullPath = "home/abc123/public_html/blah/myDir";
print substr($fullPath, strrpos($fullPath, "/") + 1);
//Output: myDir
精彩评论