Reputation: 5523
I have url like this http://example.com/dir1/dir2/dir3/dir4/Page.php?charts.htm
and I need to remove the page/extension before the querystring so it outputs http://example.com/dir1/dir2/dir3/dir4/?charts.htm
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$temp = explode( '?' , $url );
$temp[0] = ""; //remove part before the ?
Not even sure if I'm on the right track here
Upvotes: 0
Views: 71
Reputation: 43169
You can use a combination of parse_url()
and dirname()
$url = "http://example.com/dir1/dir2/dir3/dir4/Page.php?charts.htm";
$urlArray = parse_url($url); // Array ( [scheme] => http [host] => example.com [path] => /dir1/dir2/dir3/dir4/Page.php [query] => charts.htm )
$newURL = $urlArray["scheme"]."://".$urlArray["host"]."/";
$newURL .= dirname($urlArray["path"])."/?".$urlArray["query"];
// gives http://example.com/dir1/dir2/dir3/dir4/?charts.htm
Upvotes: 1