我正在使用getcwd()
返回类似这样的内容:home/abc123/public_html/blah/myDir
如何修改此字符串以返回myDir
?
答案 0 :(得分:5)
http://php.net/manual/en/function.basename.php
使用basename:
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