php - convert from british number styles to numbers only -


i have list of numbers range ones 51 , 102. when on thousand writes 2,012 or 9,216. when gets on tenthousand writes 24.1k, 87.9k. when gets on 1 million writes 1.4m or 142.5m.

problem dont know how convert readable numbers. example, 142.5m should 142500000. first step tried using this:

function cleanprice($pris)  { return preg_replace('/\d/', '', $pris); }  cleanprice($pris); 

it didnt go well. trying rid of , , . , m , k. got nowhere. there function or built php this? know number_format exist goes 1 way, , way sadly wrong way want go

function cleanprice($pris) {     $last = substr($pris, strlen($pris)-1);     switch($last) {         case "k": $scale = 1000; break;         case "m": $scale = 1000000; break;         default: $scale = 1;     }     return preg_replace('/[^-0-9.]/', '', $pris) * $scale; } 

demo


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -