码迷,mamicode.com
首页 > Web开发 > 详细

PHP简单计算器

时间:2020-02-06 16:18:09      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:put   span   def   class   lan   result   title   div   ==   

<!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简单计算器

标签:put   span   def   class   lan   result   title   div   ==   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!