RE: [PHP] is_numeric for php3

From: Date: Tue, 28 Aug 2001 22:25:09 +0000
Subject: RE: [PHP] is_numeric for php3
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-64899@lists.php.net to get a copy of this message
i think he's asking for a numeric test, not an integer test. your example looks like it should fail "3.50" (for example), even though "3.50" is a perfectly valid numeric value. personally, i think you should just use regexps. ;-) i tried to write a little is_num() type function, but i kept getting caught on split(); it seems that split() converts everything to string, no matter what. so if you try to split on the decimal point of 45.67 ... you get two strings, "45" and "67" not 45 and 67, so subsequent is_integer() calls fail (since is_integer() checks the *type* of the variable, not the *value* -- very important to keep in mind) here's what i came up with... perhaps it will be of some help to you (even though it doesnt work) function is_num($number) { // $x contains number, $y contains any decimal value list ($x, $y) = split("\.", $number); // if there's no decimal value if ( empty($y) ) { return is_int($x); } else { return ( is_int($x) && is_int($y) ); } } > -----Original Message----- > From: daniel james [mailto:cgi_guy1313@yahoo.com] > Subject: Re: [PHP] is_numeric for php3 > > do you mean, as in, > > if !is_integer($var) { > print("$var is not an integer"); > } >

« previous php.general (#64899) next »