PHP简单计算器

<!doctype html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>简单的PHP计算器</title></head><body> <form method="get" action=""> 计算 <input type="text" name="zuo" value="<?php if(isset($_GET[‘submit‘])) echo $_GET[‘zuo‘];?>"> <select name="sel"> <option value="+" <?php if(isset($_GET[‘submit‘])){if($_GET[‘sel‘] == ‘+‘) echo "selected";} ?> >+</option> <option value="-" <?php if(isset($_GET[‘submit‘])){if($_GET[‘sel‘] == ‘-‘) echo "selected";} ?> >-</option> <option value="*" <?php if(isset($_GET[‘submit‘])){if($_GET[‘sel‘] == ‘*‘) echo "selected";} ?> >*</option> <option value="/" <?php if(isset($_GET[‘submit‘])){if($_GET[‘sel‘] == ‘/‘) echo "selected";} ?> >/</option> </select> <input type="text" name="you" value="<?php if(isset($_GET[‘submit‘])) echo $_GET[‘you‘];?>"> <button name="submit" value=""> = </button> <span style="margin-left: 1rem;"> <?php if(isset($_GET[‘submit‘])){ function abc($a, $b,$c){ $result = 0; switch($c){ case ‘+‘: return $result = $a+$b;break; case ‘-‘: return $result = $a-$b;break; case ‘*‘: return $result = $a*$b;break; case ‘/‘: if($b != 0){ return $result = $a/$b; }die("除数不能为0"); break; default: echo ‘出错!‘;break; } return $result; } $z = $_GET[‘zuo‘]; $y = $_GET[‘you‘]; $v = $_GET[‘sel‘]; $x = abc($z, $y, $v); echo $x; } ?> </span> </form></body></html>

  

相关文章