Reputation: 71
I am trying to use my url to create a variable, to do so I am getting the directory as such: $dir = basename($_SERVER['REQUEST_URI'], "/index.php");
from my understanding this was supposed to remove the /index.php
aspect but then i discovered it is just for removing the extension and thus fails. My links are site.com/dir/subdir
but in the off chance someone lands on site.com/dir/subdir/index.php
i still need to get the subdir
variable. What is the best way to do this? It works fine with basename but if it goes to index.php then the variable becomes index.php instead of subdir. The issue with using .htaccess is that this is only done for 4 types of pages, not the whole site so I just need it to function this way on those pages.
Upvotes: 1
Views: 59
Reputation: 782409
I think this is what you want:
$dir = basename(dirname($_SERVER['REQUEST_URI']));
Upvotes: 2