PHP 一个简单的四则运算网页

<?php
$values = '';
if(!empty($_POST)){
    $num1 = $_POST['num1'];
    $num2 = $_POST['num2'];
    $c;
    $fuhao=$_POST['fuhao'];
    if($fuhao=='+'){
        $c=$num1+$num2;
    }else if($fuhao=='-'){
        $c=$num1-$num2;
    }else if($fuhao=='*'){
        $c=$num1*$num2;
    }else if($fuhao=='/'){
        $c=$num1/$num2;
    }else if($fuhao=='%'){
        $c=$num1%$num2;
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<form action='' method="post">
    <input type="text" name="num1">

    <select name="fuhao" id="">
        <option value="+">+</option>
        <option value="-">-</option>
        <option value="*">*</option>
        <option value="/">/</option>
        <option value="%">%</option>
    </select>
    <input type="text" name="num2">
    <input type="submit" value="=">
    <input type="text" value="<?php echo $c ;?>"><br>
</form>
</body>
</html>

  

posted @ 2022-03-28 22:14  Rebz  阅读(72)  评论(0编辑  收藏  举报