fork download
  1. <?php
  2. $total = 0;
  3. $string = '20.2*33.4';
  4. if(preg_match('/^(\d*\.?\d+)(?:\*)(\d*\.?\d+)$/', $string, $matches) === 1){
  5. $total = floatval($matches[1]) * floatval($matches[2]);
  6. }
  7. echo "$string = ".$total;
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
20.2*33.4 = 674.68