PHP计算器 PHP实现简单的计算器
浩然正气,天地长存 人气:0想了解PHP实现简单的计算器的相关内容吗,浩然正气,天地长存在本文为您仔细讲解PHP计算器的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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>
运行结果:
加载全部内容