Page 1 of 1

data types in php?

Posted: Thu Aug 18, 2005 2:32 am
by saumya
are there data types in php?i mean how can i know whethere an user has put a number in text box or its a string?Depending upon that i will put the value in databse.

Posted: Thu Aug 18, 2005 2:44 am
by n00b Saibot
you can check the type by using is_ group of functions. i.e. is_int(), is_float(), is_bool(), is_array(), is_long() just to name a few.

Posted: Thu Aug 18, 2005 3:11 am
by s.dot
Unlike many other programming languages, PHP doesn't require you to declare what type of data is being sent/received.

But if you need to verify what kind of data it is, the above post is great :-D

Posted: Thu Aug 18, 2005 4:17 am
by saumya
thanks a lot.

Posted: Thu Aug 18, 2005 6:08 am
by raghavan20
should be using gettype($mixedvar), returns the data type as string

Posted: Thu Aug 18, 2005 8:13 am
by feyd
is_numeric() works well to detect if they entered a number. The ctype_ functions could help too, however they may not be installed with your php.

Posted: Thu Aug 18, 2005 11:05 am
by BDKR
feyd wrote:is_numeric() works well to detect if they entered a number. The ctype_ functions could help too, however they may not be installed with your php.
I can't agree enough with using is_numeric(). You will most likely find that even though a person entered a number into a form field, the PHP engine is going to see it as a string. At least is_numeric() will look at that string and determine if the characters are numbers. In this case, you really aren't worried about the type of the var, but instead the type of the content.