php 计算器
<html><head><title>PHP實(shí)現(xiàn)簡(jiǎn)單計(jì)算器</title><meta http-equiv="Content-Type" content="text/html;charset=gb2312"></head> <?php$num1=true;$num2=true;$numa=true;$numb=true;$message="";//單路分支if(isset($_GET["sub"])){if($_GET["num1"]==""){$num1=false;$message.="第一個(gè)數(shù)不能為空";}if(!is_numeric($_GET["num1"])){$numa=false;$message.="第一個(gè)數(shù)不是數(shù)字";}if($_GET["num2"]==""){$num2=false;$message.="第二個(gè)數(shù)不能為空";}if(!is_numeric($_GET["num2"])){$numb=false;$message.="第二個(gè)數(shù)不是數(shù)字";}if($num1 && $num2 && $numa && $numb) {$sum=0;//多路分支switchswitch($_GET["ysf"]){case "+":$sum=$_GET["num1"]+$_GET["num2"];break;case "-":$sum=$_GET["num1"]-$_GET["num2"];break;case "x":$sum=$_GET["num1"]*$_GET["num2"];break;case "/":$sum=$_GET["num1"]/$_GET["num2"];break;case "%":$sum=$_GET["num1"]%$_GET["num2"];break;}}} ?> <br /><b>Notice</b>: Undefined index: num1 in <b> D:\\php\\PHPnow1.5.5\\Package\\vhosts\\127.0.0.1\\ceshi\\jsq.php</b> on line <b>64</b><br /><body><table align="center" border="1" width="500"><caption><h1>計(jì)算器</h1></caption><form action="jsq.php"><tr><td><input type="text" size="5" name="num1" value="<?php echo $_GET["num1"] ?>" ></td><td><select name="ysf"><option value="+" <?php if($_GET["ysf"]=="+") echo "selected" ?>>+</option><option value="-" <?php if($_GET["ysf"]=="-") echo "selected" ?>>-</option><option value="x" <?php echo $_GET["ysf"]=="x"?"selected":"" ?>>x</option><option value="/" <?php echo $_GET["ysf"]=="/"?"selected":"" ?>>/</option><option value="%" <?php echo $_GET["ysf"]=="%"?"selected":"" ?>>%</option></select></td><td><input type="text" size="5" name="num2" value="<?php echo $_GET["num2"] ?>"></td><td><input type="submit" name="sub" value="計(jì)算"></td></tr><?phpif(isset($_GET["sub"])){echo '<tr><td colspan="5">';if($num1 && $num1 && $numa && $numb){echo "結(jié)果:".$_GET["num1"]." ".$_GET["ysf"]." ".$_GET["num2"]." = ".$sum;}else{echo $message;}echo '</td></tr>';}?></form></table></body> </html>
轉(zhuǎn)自:http://1.enjoosite.sinaapp.com/archives/33?
轉(zhuǎn)載于:https://www.cnblogs.com/feiguo/archive/2012/06/04/2533564.html
總結(jié)
- 上一篇: 使用xml布局菜单
- 下一篇: c++ 的重载、覆盖、隐藏