Search code examples
phpstringurl

PHP how to get clean url from $_SERVER['REQUEST_URI'] with no parameters


is it possible that I can only get the clean url with no parameters.

this is an example.

$dis_url = $_SERVER['REQUEST_URI'];
echo $dis_url;

returns into:

'/mysite.com/subdir?message=value&message2=value2'

is it posible that it will return into:

'/mysite.com/subdir'

the parameter will not be included?

does anyone have an idea about my case? thanks in advance...


Solution

  • Use strtok and trim

    $dis_url = $_SERVER['REQUEST_URI'];
    $uri = trim(strtok($dis_url, '?'));