PHP 简单计算器
<!—calculate.php—>
<html>
<head><title>计算器</title></head>
<body>
<form action="result.php" method="post">
<table border="1">
<tr><td>第一个数</td><td><input type="text" name="num1"></input></td></tr>
<tr><td>第二个数</td><td><input type="text" name="num2"></input></td></tr>
<tr>
<td>运算符</td>
<td>
<select name="oper">
<option value="+">加</option>
<option value="-">减</option>
<option value="*">乘</option>
<option value="/">除</option>
</td>
</tr>
<tr><td colspan="2"><input type="submit" value="结果"></input></td></tr>
</table>
<form>
</body>
</html>
<head><title>计算器</title></head>
<body>
<form action="result.php" method="post">
<table border="1">
<tr><td>第一个数</td><td><input type="text" name="num1"></input></td></tr>
<tr><td>第二个数</td><td><input type="text" name="num2"></input></td></tr>
<tr>
<td>运算符</td>
<td>
<select name="oper">
<option value="+">加</option>
<option value="-">减</option>
<option value="*">乘</option>
<option value="/">除</option>
</td>
</tr>
<tr><td colspan="2"><input type="submit" value="结果"></input></td></tr>
</table>
<form>
</body>
</html>
<!—result.php—>
<?php
$num1 = $_REQUEST['num1'];
$num2 = $_REQUEST['num2'];
$oper = $_REQUEST['oper'];
$result = 0;
switch ($oper)
{
case "+":
$result = $num1 + $num2;
break;
case "-":
$result = $num1 - $num2;
break;
case "*":
$result = $num1 * $num2;
break;
case "/":
$result = $num1 / $num2;
break;
}
echo "$result";
?>
<a href="calculate.php">返回计算页面</a>