PHP实现简单的计算器
吾爱主题
阅读:102
2021-10-25 14:08:00
评论:0
本文实例为大家分享了php实现简单计算器的具体代码,供大家参考,具体内容如下
caculator.php
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | < html > < head > </ head > < body > <? php if (!empty($_POST)) { $data1 = $_POST["data1"]; $data2 = $_POST["data2"]; $fuhao = $_POST["fuhao"]; $ result = "" ; echo $data1; echo $data2; echo $fuhao; echo $result; if ($fuhao == '+') { $result = $data1 + $data2; } else if ($fuhao == '-') { $result = $data1 - $data2; } else if ($fuhao == '*') { $result = $data1 * $data2; } else if ($fuhao == '/') { $result = $data1 / $data2; } } else { $ data1 = "" ; $ data2 = "" ; $ fuhao = "" ; $ result = "" ; } ?> < form action = "caculator.php" method = "post" > < input type = "text" name = "data1" value="<?php echo $data1; ?>"/> < select name = "fuhao" > < option value = "+" <?php if ($fuhao == "+") { echo ' selected = "selected" '; } ?>>+ </ option > < option value = "-" <?php if ($fuhao == "-") { echo ' selected = "selected" '; } ?>>- </ option > < option value = "*" <?php if ($fuhao == "*") { echo ' selected = "selected" '; } ?>>* </ option > < option value = "/" <?php if ($fuhao == "/") { echo ' selected = "selected" '; } ?>>/ </ option > </ option > </ select > < input type = "text" name = "data2" value="<?php echo $data2; ?>"/> < input type = "submit" value = "=" /> < input name = "result" type = "text" value="<?php echo $result; ?>"/> < input type = "reset" /> </ form > </ body > </ html > |
运行结果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/u011842599/article/details/89674002
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。