PHP中计算器简单算法

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>计算器</title>
</head>
<body>
<?php
@$first =$_GET['first'];
@$yunsuan =$_GET['yunsuan'];
@$second =$_GET['second'];
$result = '=';


?>
<form action="">
<span>第一个数:</span><input type="text" name="first" value=<?php echo @$first?>>
<br>
<input type="radio" name="yunsuan" value="+">+<input type="radio" name="yunsuan" value="-">-
<input type="radio" name="yunsuan" value="*">*<input type="radio" name="yunsuan" value="/">/
<br>
<span>第二个数:</span><input type="text" name="second" value=<?php echo @$second?>>
<br>
<input type="submit" value="计算"/>
</form>
<?php echo $first.$yunsuan.$second;
switch($yunsuan) {
case '+':
echo $result.($first + $second);
break;
case '-':
echo $result.($first - $second);
break;
case '*':
echo $result.($first * $second);
break;
case '/':
echo $result.($first / $second);
break;
}?>

</body>
<html>
posted @ 2017-03-15 16:44  兰亭小白泛曲溪  阅读(131)  评论(0编辑  收藏  举报