note 14802 added to function.is-int.php

From: Date: Wed, 15 Aug 2001 13:05:04 +0000
Subject: note 14802 added to function.is-int.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-16750@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 http://www.php.net/manual/en/function.is-int.php

« previous php.notes (#16750) next »