Skip to content

Instantly share code, notes, and snippets.

@durango
Created May 6, 2012 14:58
Show Gist options
  • Select an option

  • Save durango/2622789 to your computer and use it in GitHub Desktop.

Select an option

Save durango/2622789 to your computer and use it in GitHub Desktop.
Just showing someone how to convert 1k10 to 1,010.
function money_commands($dep) {
$total = 0;
$dep = str_replace(',', '', $dep);
preg_match_all('#[0-9]{1,}(m|M)#', $dep, $matches);
foreach($matches AS $v) {
foreach($v AS $val) {
$x = str_ireplace('m', '', $val);
$dep = str_replace($val, '', $dep);
$total += $x*1000000;
}
}
preg_match_all('#[0-9]{1,}(t|T|k|K)#', $dep, $matches);
foreach($matches AS $v) {
foreach($v AS $val) {
$x = str_ireplace(array('k','t'), '', $val);
$dep = str_replace($val, '', $dep);
$total += $x*1000;
}
}
preg_match_all('#[0-9]{1,}(h|H)#', $dep, $matches);
foreach($matches AS $v) {
foreach($v AS $val) {
$x = str_ireplace('h', '', $val);
$dep = str_replace($val, '', $dep);
$total += $x*100;
}
}
$total += $dep;
if(!is_numeric($total)) $amount = 0;
else $amount = $total;
return $amount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment