-
-
Save ladaposamuel/769f1652f841cace1bee4e75511d3df8 to your computer and use it in GitHub Desktop.
Unformats a number formatted with number_format().
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function number_unformat($number, $force_number = true, $dec_point = '.', $thousands_sep = ',') { | |
if ($force_number) { | |
$number = preg_replace('/^[^\d]+/', '', $number); | |
} else if (preg_match('/^[^\d]+/', $number)) { | |
return false; | |
} | |
$type = (strpos($number, $dec_point) === false) ? 'int' : 'float'; | |
$number = str_replace(array($dec_point, $thousands_sep), array('.', ''), $number); | |
settype($number, $type); | |
return $number; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment