首页 > Web开发 > 详细

PHP简单计算器

时间:2020-02-06 16:12:07      阅读:71      评论:0      收藏:0      [点我收藏+]
<!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>

  

PHP简单计算器

原文:https://www.cnblogs.com/whales/p/12268955.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!