开发者

How can I get the name of the current directory - not the whole path? [duplicate]

This question already has answers here: Closed 11 years ago.

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜