PHP简单计算器
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta 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" value="<?php if(isset($_GET[‘submit‘])) echo $_GET[‘zuo‘];?>"> <select> <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="http://www.mamicode.com/" <?php if(isset($_GET[‘submit‘])){if($_GET[‘sel‘] == ‘/‘) echo "selected";} ?> >/</option> </select> <input type="text" value="<?php if(isset($_GET[‘submit‘])) echo $_GET[‘you‘];?>"> <button value=""> = </button> <span> <?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>
,温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/30449.html