I was using is_numeric to validate integers coming from POST data like:
if( ! is_numeric($_POST['integer_string'])) return FALSE // not a integer
Then I discovered is_numeric will return TRUE if the value has a decimal.
Next I tried casting and is_int:
$int = (int) $_POST['numeric_string'];
if( ! $int) return FALSE // not a integer
But casting will cut the integer after a non numeric value is passed.
$int = '222i2';
echo $int;
// 222
The integer I'm attempting to validate will be used in WHERE clauses in SQL to identify integer primary keys.
What is a fool proof way to validate an integer from POST data or how do you personally deal with this problem?