In PHP, is there an easy way to get only part of the HTTP URI directory? That is, given the URI with an optional file name and request, I only want a directory without a file or request name;
Given returns
///
/a.txt /
/? x = 2 /
/a.txt?x=2 /
/ foo / / foo /
/foo/b.txt / foo /
/foo/b.txt?y=3 / foo /
/ foo / bar / / foo / bar /
/foo/bar/c.txt / foo / bar /
Etc.
I can not find the PHP function for this. I am using the following code snippet, but it is long and overly complex for something that seems to be one function;
$uri_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$uri_dir = substr($uri_path, 0, 1 + strrpos($uri_path, '/'));
Is there a cleaner way?
Edit
dirname () does not do what I want.
echo dirname("/foo/bar/");
Outputs;
/foo
source