开发者

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

开发者 https://www.devze.com 2023-03-19 19:05 出处:网络
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
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

精彩评论

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