Actually, on second thought I might do it this way:
if (isset($_REQUEST['opt'], $_REQUEST['one'], $_REQUEST['two'])) {
$result = 'Error: invalid operator';
switch ($_REQUEST['opt']) {
case '+':
$result = $_REQUEST['one'] + $_REQUEST['two'];
break;
case '-':
$result = $_REQUEST['one'] - $_REQUEST['two'];
break;
case '*':
$result = $_REQUEST['one'] * $_REQUEST['two'];
break;
case '/':
$result = $_REQUEST['one'] / $_REQUEST['two'];
break;
}
echo $result;
}
Basically, the PHP interpreter has no way of knowing what your input means, even though '+' and '-' make alot of sense to you. As such, you need to map the input to the operations, and one way of doing that is shown above.