Sending http_get_vars array as parameter
| From: | H�kan Askengren | Date: | Tue, 02 Jan 2001 23:03:59 +0000 |
| Subject: | Sending http_get_vars array as parameter | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-32398@lists.php.net to get a copy of this message | ||
Hi
I use a loop to strip posted variables from some unwanted characters.
I have tried to make a function out of it but with no success.
Can anyone explain why?
// Not working loop in function making the same as working loop below:
// Function accepts an array by reference.
function trimVars(&$http_vars){
for(reset($http_vars); $key=key($http_vars);next($http_vars)) {
$this = stripslashes($http_vars[$key]);
$this = ereg_replace(">|<|\"|\||`|\\\\",'',$this);
$this = ereg_replace(" ",' ',$this);
$this = trim($this);
$$key = addslashes($this);
}
}
// Just copying the posted vars:
$http_vars1 = $HTTP_GET_VARS;
$http_vars2 = $HTTP_GET_VARS;
// Here I try with the function:
trimVars($http_vars1);
// Here the same thing as plain script:
for(reset($http_vars2); $key=key($http_vars2);next($http_vars2)) {
$this = stripslashes($http_vars2[$key]);
$this = ereg_replace(">|<|\"|\||`|\\\\",'',$this);
$this = ereg_replace(" ",' ',$this);
$this = trim($this);
$$key = addslashes($this);
}
The $http_vars2 are now stripped from the unwanted characters,
but NOT the $http_vars1 from the function.
Does somebody know why this wont work in function above?
Best regards
Håkan