data types in php?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

data types in php?

Post 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.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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
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.
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

thanks a lot.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

should be using gettype($mixedvar), returns the data type as string
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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.
Post Reply