note 24981 deleted from function.is-numeric by crell

From: Date: Mon, 18 Apr 2022 14:58:37 +0000
Subject: note 24981 deleted from function.is-numeric by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218286@lists.php.net to get a copy of this message
Note Submitter: eagleflyer2 at lycos dot com ---- 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#...}

« previous php.notes (#218286) next »