Ask Your Question
2

Is there a way to obtain the URL without the query string?

asked 2023-05-02 02:39:20 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-05-02 03:03:02 +0000

huitzilopochtli gravatar image

Yes, you can obtain the URL without the query string by using the parse_url() and http_build_query() functions in PHP.

First, use the parse_url() function to parse the current URL and extract the path and query string:

$url = $_SERVER['REQUEST_URI'];
$parsed = parse_url($url);
$path = $parsed['path'];
$query_string = isset($parsed['query']) ? $parsed['query'] : '';

Then, use the http_build_query() function to rebuild the URL without the query string:

$url_without_query = $path;
if (!empty($query_string)) {
    $url_without_query .= '?' . http_build_query(array());
}

This will give you the URL without the query string.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-02 02:39:20 +0000

Seen: 8 times

Last updated: May 02 '23