note 24981 added to function.is-numeric

From: Date: Fri, 06 Sep 2002 18:02:25 +0000
Subject: note 24981 added to function.is-numeric
Groups: php.notes 
Request: Send a blank email to php-notes+get-36255@lists.php.net to get a copy of this message
Hi ! Many of you may have experienced that the 'is_numeric' function seems to fail always when form entries are checked against their variable type. So the function seems to return 'false' even if the form entry was aparently a number or numeric string. The solution is pretty simple and no subroutines or fancy operations are necessary to make the 'is_numeric' function usable for form entry checks: Simply strip off all (invisible) characters that may be sent along with the value when submitting a form entry. Just use the 'trim' function before 'is_numeric'. Example: $variable = trim($variable); if (is_numeric($variable) {...#do something#...} else {...#do something else#...} -- http://www.php.net/manual/en/function.is-numeric.php http://master.php.net/manage/user-notes.php?action=edit+24981 http://master.php.net/manage/user-notes.php?action=delete+24981 http://master.php.net/manage/user-notes.php?action=reject+24981

« previous php.notes (#36255) next »