Code Lover Code Lover - 1 year ago 75
PHP Question

PHP: Get last directory name from path

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.


I wan to get only
from above path. Here site_root is nothing but
So how can I get only


Answer Source

Easiest way would be to use basename($yourpath) as you can see here:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download