I am writing one function for getting some different database query. Now things are going well but only need to get last directory name from defined path.
$qa_path=site_root('/learnphp/docs/');
I wan to get only docs
from above path. Here site_root is nothing but $_SERVER['DOCUMENT_ROOT']
So how can I get only docs
?
Thanks
Easiest way would be to use basename($yourpath)
as you can see here: http://php.net/basename
Provided answer doesn't work if your string contains the file at the end, like :
basename('/home/mypath/test.zip');
gives
test.zip
So if your string contains the file, don't forget to dirname it first
basename(dirname('/home/mypath/test.zip'));
gives
mypath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With