PHP实现简单的计算器
本文实例为大家分享了PHP实现简单计算器的具体代码,供大家参考,具体内容如下
caculator.php
<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>
运行结果:
相关推荐
MXstudying 2020-09-05
WasteLand 2020-09-15
Noneyes 2020-11-10
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28