In PHP, how do I distinguish between a number as a string [0-9] versus an operator (+-*/) or letter [A-Za-z]?
I tried this, but intval also converts the type of nonnumbers to ints as well:
is_int(intval($somestr));
Is regex the way to do it?
In PHP, how do I distinguish between a number as a string [0-9] versus an operator (+-*/) or letter [A-Za-z]?
I tried this, but intval also converts the type of nonnumbers to ints as well:
is_int(intval($somestr));
Is regex the way to do it?
Use the ctype functions. E.g.:
$isNumeric = ctype_digit('123123');
try is_numeric()
is_numeric gives true by f. ex. 1e3 or 0xf5 too. So it's not the same as ctype_digit, which just gives true when only values from 0 to 9 are entered. ref