本文实例为大家分享了PHP实现简单计算器的具体代码,供大家参考,具体内容如下
caculator.php
<html> <head> </head> <body> <"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 = ""; } "caculator.php" method="post"> <input type="text" name="data1" value="<"/> <select name="fuhao"> <option value="+" <"+") { echo 'selected="selected"'; } "-" <"-") { echo 'selected="selected"'; } "*" <"*") { echo 'selected="selected"'; } "/" <"/") { echo 'selected="selected"'; } "text" name="data2" value="<"/> <input type="submit" value="="/> <input name="result" type="text" value="<"/> <input type="reset"/> </form> </body> </html>
运行结果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
标签:
PHP,计算器
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com
暂无“PHP实现简单的计算器”评论...