RE: [PHP] is_numeric for php3

From: Date: Tue, 28 Aug 2001 22:42:04 +0000
Subject: RE: [PHP] is_numeric for php3
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-64905@lists.php.net to get a copy of this message
Ahhh, in that context, with is_integer(), i think you're partially right. however, i looked it up, and is_numeric() will work fine. http://www.php.net/manual/en/function.is-numeric.php btw-- as for the regexps, none for me, thanks ;) those things give me the heebie-jeebies. --- "scott [gts]" <scott@graphictype.com> wrote: > 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"); > > } > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: > php-general-unsubscribe@lists.php.net > For additional commands, e-mail: > php-general-help@lists.php.net > To contact the list administrators, e-mail: > php-list-admin@lists.php.net > __________________________________________________ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/

« previous php.general (#64905) next »