Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199901

Re: [PHP3] $HTTP_POST_VARS From: Rasmus Lerdorf (rasmus <email protected>)
Date: 01/09/99

> 1) WHY? What did I do wrong in this case?

Because $HTTP_POST_VARS is just a copy of the data. The global namespace
may or may not contain these same values, so it cannot be an actual
reference to the data since the global version of the variable may have
been changed by any number of things (like GET or Cookie data or even the
user manually). You are in fact just changing the copy as you have
discovered.

> 2) In fact is there a better way to accomplish what I intended?
> i.e. To remove all spaces from the beginning and end of the string,
> to condense excessive spaces " +" to single space " ", and
> to strip all HTML tags
> for all user inputs

Sure, I would do it like this:

    while(list($key,$value) = each($HTTP_POST_VARS)) {
        $$key = ...manipulate $value somehow...;
    }

You can't really use array_walk() for this because it operates on the
value of the associative array only, and you need to know the key part
because that is what contains the variable name. By using a variable
variable (the $$) you are manipulating the variable by that name.

Now, if this is going to be done in a separate function you would want to
use $GLOBALS[$key] instead of $$key. $GLOBALS[$key] and $$key are
synonymous in this case.

-Rasmus

--
PHP 3 Mailing List   http://www.php.net/
To unsubscribe send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest list:  php3-digest-subscribe <email protected>
For help: php3-help <email protected>  Archive:  http://www.php.net/mailsearch.php3
List administrator:  zeev <email protected>