W3docs

Request string without GET arguments

In PHP, you can use the $_SERVER['REQUEST_URI'] variable to get the request string without GET arguments.

In PHP, $_SERVER['REQUEST_URI'] includes the query string by default. To get the request path without GET arguments, you can use the parse_url() function. For example, if the full URL being accessed is http://example.com/page.php?id=5, parse_url() will extract /page.php.

Example of using parse_url() to get the request path without GET arguments in PHP

$url = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

This will give you the path of the URL requested by the client.

Alternatively, you can split the string at the question mark: explode('?', $_SERVER['REQUEST_URI'])[0].