[solved] if condition does not equal INT

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
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

[solved] if condition does not equal INT

Post by robster »

How do you do that?!

:)

I've got a database field with text in it which is now slowly being replaced by an integer reference instead.

Code: Select all

IE:  "fluffy shampoo" is now  "1".
What I'm trying to do is this kind of error checking:

Code: Select all

if field data IS NOT an INT
{
do stuff with a function that expects an INT
}
else
{
echo "this is old data";
}

So, how does one read a value and determine if there's text or an integer in there?

bizzarro!!

:)

Rob
Last edited by robster on Wed Sep 21, 2005 12:47 am, edited 1 time in total.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

is_int()

http://us3.php.net/manual/en/function.is-int.php

or

Code: Select all

ereg('[^0-9]', $int)
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post by robster »

is there NOTHING that is not easily do-able with PHP?! LOL :)

Thank you so much. They've thought of everything have they not!?

(looks like this is the function I'm after btw, very similar, but slightly different: http://us3.php.net/manual/en/function.is-numeric.php)

rob
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Is Numeric and is Int are two different things... :) :)
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post by robster »

true, I think I asked my question slightly incorrectly.

It was the ability to test for a numeric value rather than an INT value.
But I was lead straight to the answer, which I really appreciate.

Thanks again,

rob
Post Reply