3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function get_numerics ($str) { preg_match_all('/\d+/', $str, $matches); return $matches[0]; } $input = 'bubur 98k'; $inputNumbers = get_numerics($input); if (count($inputNumbers) !== 1) { // lebih dari 1 angka, atau angka null print_r("formatnya yang bener dong."); } else { $tempExpense = $inputNumbers[0]; // get index of first number occurence $pos = strpos($input, (string)$tempExpense); $k = ""; if (substr($input, $pos+1,1) === 'k') { // 3k $expense = $tempExpense * 1000; } elseif (substr($input, $pos+1,1) === '.') { // 100.300 } else { // 5000 $expense = $tempExpense; } print_r($tempExpense."k \n"); print_r($expense); }
based on ffjuD
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0beta1
98k 98