<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Calculator</title>
<style>
#container {
width: 180px;
margin-left: auto;
margin-right: auto;
}
.input {
width:100%
}
.text{
text-align:center;
}
</style>
</head>
<body>
<div class="text">
<h2>计算器</h2>
</div>
<div id = "container">
<form method = 'post'>
<input type="text" name = 'a'>
<select name="ch">
<option value="">+</option>
<option value="">-</option>
<option value="">*</option>
<option value="">/</option>
</select>
<input type="text" name = 'b'>
<p>answer:</p>
<input type="submit" value="等于">
</form>
</div>
<?php
@$a = $_POST['a'];
@$b = $_POST['b'];
@$ch = $_POST['ch'];
function add($a,$b) {
return $a + $b;
}
function sub($a,$b) {
return $a - $b;
}
function mul($a,$b) {
return $a * $b;
}
function div($a,$b) {
return $a / $b;
}
$fun;
switch ($ch) {
case "+":
$fun = 'add';
break;
case "-":
$fun = 'sub';
break;
case "*":
$fun = "mul";
break;
case "/":
$fun = "div";
break;
default:
break;
}
function getAnswer($t1,$t2,$callback) {
return $callback($t1, $t2);
}
echo getAnswer($a, $b, $fun);
?>
</body>
</html>
- 2 回答
- 0 关注
- 462 浏览
添加回答
举报
0/150
提交
取消