17-php计算器

来源:互联网 发布:阿里云 更改域名 编辑:程序博客网 时间:2024/05/22 10:41

phpMycalc.php


<html><head><title>php计算器</title><meta http-equiv="content-type" content="text/html;charset=UTF-8"/></head><body><form action="result.php" method="post">   请输入第一个数字:<input type="text" name="num1"/><br/>   请输入第二个数字:<input type="text" name="num2"/><br/>   请选择操作运算符:<select name="oper">                    <option value="+">+</option><option value="-">-</option><option value="*">*</option><option value="/">/</option></select><input type="submit" value="得到结果"/></form></body></html>

result.php

<?php   $num1=$_REQUEST['num1'];   $num2=$_REQUEST['num2'];   $oper=$_REQUEST['oper'];   $result=0;   switch($oper){    case '+':$result=$num1+$num2; echo 'num1+num2='.$result;break;case '-':$result=$num1-$num2; echo 'num1-num2='.$result;break;case '*':$result=$num1*$num2; echo 'num1*num2='.$result;break;case '/':$result=$num1/$num2;     echo 'num1/num2='.$result;break;defalut:echo '输入的运算符是不正确的!';   }   ?>


要点:$_REQUEST得到表单中的数据。




原创粉丝点击