On Tuesday, June 25, 2002, at 03:22 PM, Erik Price wrote:
> However, I don't like using $_SERVER['QUERY_STRING'] because if there
> are empty GET variables, it grabs them. So, if you prefer, you can do
> this:
>
> $getVarsArr = array();
> foreach ($_GET as $getVarName => $getVarVal) {
> $getVars[] = $getVarName . "=" . $getVarVal;
> }
> $getVarsStr = implode("&", $getVars);
> $request = "http://" . $_SERVER['HTTP_HOST'] . "/" .
> $_SERVER['PHP_SELF'] . "?" . $getVarsStr;
Doh, I forgot the part where you test for empty -- amend the above in
the following fashion:
$getVarsArr = array();
foreach ($_GET as $getVarName => $getVarVal) {
if (!empty($getVarVal)) {
$getVars[] = $getVarName . "=" . $getVarVal;
}
}
$getVarsStr = implode("&", $getVars);
$request = "http://" . $_SERVER['HTTP_HOST'] . "/" .
$_SERVER['PHP_SELF'] . "?" . $getVarsStr;
Why would you care if there were empty GET vars? Well, if you had a big
search engine or some other form where the user can specify a bunch of
criteria or just a little bit, it's up to you. It's nice if you have to
grab the GET data for whatever reason (repopulating links, etc) and you
don't waste time with huge querystrings made up of mostly-empty
variables.
Erik
----
Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php