Take a look at this previous question .
Hoohaah suggesting using strstr () is pretty nice. Will the following lines return from the beginning of the line to the first ? (the third argument to strstr () is only available for PHP 5.3.0):
echo strstr($_SERVER["REQUEST_URI"], "?", TRUE);
Or, if you want to stick to explode, you can use if list () . (2 indicates that no more than 2 elements will be returned by the explosion).
list($url) = explode("?", $_SERVER["REQUEST_URI"], 2); echo $url;
Finally, to use the initially available PHP parking ,
$info = parse_url($_SERVER["REQUEST_URI"]); echo $info["scheme"] . "://" . $info["host"] . $info["path"];
Peter Ajtai
source share