data types in php?
Moderator: General Moderators
data types in php?
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.
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
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.
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
But if you need to verify what kind of data it is, the above post is great
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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.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.