3 ms·
At this point you're writing the parser that ships in most language's standard libraries. And, if you naïvely use the suggested function for the purpose you've
by deathanatos 5y ago
At this point you're writing the parser that ships in most language's standard libraries.
And, if you naïvely use the suggested function for the purpose you've suggested it for, e.g., like,
if(!is_numeric($input)) { error(); }
else { return (int)$input; }
…you'll parse a lot of strings that still aren't valid integers. (E.g., "2e-2" is "numeric" and would thus parse.)