Created
December 21, 2011 02:07
-
-
Save msng/1504235 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
Thanks!