Take a look at the evalMath class on PHPClasses, which can handle quite complex formulae.
Alternatively:
$string = '2 + 2';
list($operand1,$operator,$operand2) = sscanf($string,'%d %[+\-*/] %d');
switch($operator) {
case '+' :
$result = $operand1 + $operand2;
break;
case '-' :
$result = $operand1 - $operand2;
break;
case '*' :
$result = $operand1 * $operand2;
break;
case '/' :
$result = $operand1 / $operand2;
break;
}
echo $result;