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
This will help you
This is the easiest way:
getcwd() = give your full directory path basename() = give you last directory
This gives you the current directory name:
echo basename(dirname(__FILE__));
you can use this simple snippet:
Try
explode('/', '/learnphp/docs/')
to split the string into array locations. Then fetch the last location.Here is more info: http://php.net/manual/en/function.explode.php