Converting number abbreviations (5.2k, 1.7m, etc) into valid integers with PHP -


I have a column that has several numbers written in "shortcodes", for example:

For 5k - 86.6 to 86,600 / 4.1 meters for 4,100,000, 1.2b to 1.2200 million

I want to do some numbers for a PHP frame but I want to do this Need to convert to valid integer How do I do this with PHP?

something like this:

  switch (stroller (substr ($ input , -1))) {case 'k': $ input * = 1000; break; // Similarly, M, M, B, B.}   

Assume that your data is well formatted I will not require further checks:

  if (! Preg_match ('/ ^ \ d + (?: \. \ D +)? [MBK] $ / i', $ input) {// $ input is not a valid format}    

Comments