PHP: intval() equivalent for numbers >= 2147483647
Try this function, it will properly remove any decimal as intval does and remove any non-numeric characters.
<?phpfunction bigintval($value) { $value = trim($value); if (ctype_digit($value)) { return $value; } $value = preg_replace("/[^0-9](.*)$/", '', $value); if (ctype_digit($value)) { return $value; } return 0;}// SOME TESTINGecho '"3147483647.37" : '.bigintval("3147483647.37")."<br />";echo '"3498773982793749879873429874.30872974" : '.bigintval("3498773982793749879873429874.30872974")."<br />";echo '"hi mom!" : '.bigintval("hi mom!")."<br />";echo '"+0123.45e6" : '.bigintval("+0123.45e6")."<br />";?>
Here is the produced output:
"3147483647.37" : 3147483647"3498773982793749879873429874.30872974" : 3498773982793749879873429874"hi mom!" : 0"+0123.45e6" : 0
Hope that helps!