I've got field in my database which contain strings like 21;48;33;22;31. Then I'd like to convert it to mathematical calculation 21+48+33+22+31.
$points = "21;48;33;22;31"; $points = str_replace(";","+",$points ); $points = preg_replace('/[^0-9\+\-\*\/\s]+/', '', $points); echo $points; But that simply does not work. I've got the same string "21+48+33+22+31" instead of the sum.
array_sum(explode(';', $points));