I’m looking for numerics in a variable, and if not found I quote the string – otherwise it is left unquoted. Example:
$x = '000916846E38516';
if (is_numeric($x)) { echo 'Numeric!'; } else { echo 'Non-numeric!'; }
It so happens that the string is scientific notation, and PHP recognizes it as a number. How should I work around this? Would just checking to see if there are alpha characters be better, or is there another function similar to is_numeric that will exclude scientific numbers?
is_int()andctype_digit()should both work for you.filter_var()might be even better as you can set flags to validate floats (FILTER_VALIDATE_FLOAT) and integers (FILTER_VALIDATE_INT)