note 14802 deleted from function.is-int by jimw

From: Date: Thu, 20 Dec 2001 23:34:34 +0000
Subject: note 14802 deleted from function.is-int by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-23576@lists.php.net to get a copy of this message
Note that output from a form field and variables on a query string are always text/strings. Try converting them beforehand, alternatively you may wish to devise a function which removes non-numeric characters, e.g: function fnStripNonNum($str){ $str=(string)$str; for($i=0; $i<strlen($str); $i++){ if( ord($str[$i])>=ord('0') && ord($str[$i])<=ord('9') ){ $output.=$str[$i]; } } return $output; } This is more strict than the "is_something()" family of functions because it makes sure that there are no E's, -'s and decimal points because it compares the ASCII values of each character. This is handy for processing phone numbers and storing dates. (I like to store dates as yyyymmdd because I don't have to convert them into something that's meaningless to me, like the number of seconds since 01/01/1970, and I can still do basic inequality maths with them i.e. is this date >= that date and so on) -Paul M

« previous php.notes (#23576) next »