Possible Duplicate:
How to get the last dir from a path in a string
我正在使用getcwd()
返回类似这样的内容:home/abc123/public_html/blah/myDir
如何修改此字符串以简单地返回 myDir
?
最佳答案
http://php.net/manual/en/function.basename.php
使用基本名称:
print basename("home/abc123/public_html/blah/myDir");
//Output: myDir
或者strpos
和substr
:
$fullPath = "home/abc123/public_html/blah/myDir";
print substr($fullPath, strrpos($fullPath, "/") + 1);
//Output: myDir
关于php - 如何获取当前目录的名称 - 而不是整个路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6643922/