RE: [PHP] how do i get a variable type? - not that simple

From: Date: Tue, 20 Mar 2001 16:24:16 +0000
Subject: RE: [PHP] how do i get a variable type? - not that simple
Groups: php.general 
Request: Send a blank email to php-general+get-44765@lists.php.net to get a copy of this message
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

« previous php.general (#44765) next »