Re: variable ?
| From: | Philip Olson | Date: | Mon, 18 Dec 2000 21:18:20 +0000 |
| Subject: | Re: variable ? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-30926@lists.php.net to get a copy of this message | ||
Consider the empty function.
http://www.php.net/manual/function.empty.php
And the strlen function.
http://www.php.net/manual/function.strlen.php
For the paranoid at heart, AFAIK, if($var != '') will cause errors if
error settings are high enough and besides, i find empty to be prettier :)
although doing form checking outside of "if empty or not" is prefered.
Look into ereg() for example.
But, regarding Teodors comment, the idea of using arrays was the important
point in this question imho, which is a good point to consider. Arrays
are your friend. As are $HTTP_GET_VARS and $HTTP_POST_VARS.
Regards,
Philip
--.sig
[ Want to write Good code? First, write Bad code. ]
On Mon, 18 Dec 2000, JB wrote:
> Well, he wanted to check if a field was set. Using isset($varname) will not
> work, because even if a form/field is not filled out, the variable is still
> set and passed along, its just set to nothing ( "" ). So do a
> if($var!=""){
> print "This Variable Has Been Set!";
> }
> else {
> print "This Variable Was Not Set!";
> }
>
> ----- Original Message -----
> From: Teodor Cimpoesu <teo@digiro.net>
> To: <php-general@lists.php.net>
> Sent: Monday, December 18, 2000 8:57 PM
> Subject: Re: [PHP] variable ?
>
>
> > Hi Mike!
> > On Mon, 18 Dec 2000, Mike wrote:
> >
> > > I have a form that passes 4 of a possible 8 variables to a script.How
> can I
> > > tell which 4 were passed?
> > > Mike P
> > > mpeloso@princeton.edu
> > here's my favourite: user arrays, namely instead of <input name="var1"
> ...>
> > use <input name="vars[foo]" ...> so on, then you simply say :
> > $stuff = $vars['foo'];
> > or the careful programmer with E_ALL and all, would write something along:
> > isset($vars['foo']) && ($stuff = $vars['foo']);
> >
> > cheers,
> >
> > -- teodor
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail: php-list-admin@lists.php.net
> >
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>