View Full Version : Need Help
I have a table that is set to varchar(50) and I put both numbers and letter in it... now I cant figure out how to get this code to work..... i always returns string even with numbers..
if (!is_int($userinfo[table])) {
echo "String<br>";
} else {
echo "Integer<br>";
}
can anyone help?
Xenon
05-29-2002, 08:10 PM
i'm not sure, but doesn't mean varchar(50) that it is always a string with 50 chars like: "12345 " is a string.
try !is_int(trim($userinfo[table]))
but i'm not sure ;)
I was thinking that. I just needed a second opinion. ;)
Hmm... doesnt work. Damn this is a pain...
Logician
05-30-2002, 09:18 AM
in PHP there is no strict variable types: every string can be an integer and every integer can be a string.
eg. if you have a string like "45asda23" and use it as an integer, you can, php will convert it to 45.
So what exactly trying to do with this code? In other words when you want your script to return "integer" result?
if you want to return integer when there is no chars in the string except a number, you can use this:
if ((string)($userinfo[table])!=(int)($userinfo[table]))
{
echo "String<br>";
}
else
{
echo "Integer<br>";
}
or try "is_numeric" :
if (is_numeric($userinfo[table]))
{
echo "Integer<br>";
}
else
{
echo "String<br>";
}
is_int checks the variable type only, not the context of variable..
Regard,
Logician
Admin
05-30-2002, 09:32 AM
Also bear in mind, that like forms, MySQL will always return data as a string, even if the field is INT. So yes, is_numeric() is the best way to do this.
Another method would be:
if ($variable == ($variable + 0)) {
// It's a number
}
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.