Under some conditions (I haven't determined which)
if ($input_var_from_form == "")
doesn't work, but
if (strlen($input_var_from_form) == 0)
does.
Rudolf Visagie
[EMAIL PROTECTED]
-----Original Message-----
From: Dennis Gearon [mailto:[EMAIL PROTECTED]]
Sent: 20 March 2001 06:24
To: [EMAIL PROTECTED]
Subject: RE: [PHP] how do i get a variable type? - not that simple
I discovered the same thing, that all values from text fields ARE
text, i.e. strings. Also, that an empty field IS set upon return,
soooooooo...........
To check for empty field, check for empty STRING equivalence:
if ( $input_var_from_form == "" ){
Do something because filed is empty;
} else {
Do something because filed has a value;
}
To make a 'safe' casting from the input string to an int, I test
for the above test in combination with requiring the first
char in the field to be a number. I wasn't worried that
they all were numbers. This comes to .....
if ( $input_var_from_form == "" || ! egrep( "^[0-9]",
$input_var_from_form ){
Do something because not an int;
} else {
$input_var_from_form = (int) $input_var_from_form;
Do something because it IS an in;
}
I'm sure there's similar things that could be done for a float, or if an
object
was being filled by a set of form fields, all the fields would be tested
the
same way as the object filled itself.
Dennis Gearon
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]