php写一个简单的计算器
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>计算器</title> </head> <body> <form method="post"> <table align="center"> <tr> <td align="center">第一个数</td><td><input type="text" name="first"></td> </tr> <tr> <td colspan="2" align="center"> <input type="radio" name="operator" value="+">+ <input type="radio" name="operator" value="-">- <input type="radio" name="operator" value="*">* <input type="radio" name="operator" value="/">/ </td> </tr> <tr> <td align="center">第二个数</td><td><input type="text" name="second"></td> </tr> <tr> <td> <input type="submit" value="提交"></td> </tr> </table> </form> <?php header("content-type:text/html;charset=utf-8"); $first=$_POST['first']; $second=$_POST['second']; $operator=$_POST['operator']; echo '结果为:'; if ( $operator == '+' ) { echo $first+$second; } if($operator == '-') { echo $first-$second; } if($operator == '*') { echo $first*$second; }if($operator == '/') { echo $first/$second; } ?> </body> </html>
这个会报警告:
上网查了一下,因为接收了空值,所以报的这个警告。
所以这个东西可以不用管。
解决方法:
https://www.baidu.com/link?url=gy5XGLhoRy8bUMPZLMcTGuWl7nQKAXt9Zrn642HRBhAcZS5oRax1KFrga5IqAxzXlKs5Xv3qGnc68AjakEKIW_&wd=&eqid=bb0491f00000160a000000025ae170a7
运行结果:
https://necydcy.me/