放假
预习了一点PHP的知识,感觉自己的装的集成环境好像有点问题啊,表单的数据提交给php文件之后不能正常翻译,网页把php代码全翻译出来的,真是一脸懵逼啊...
<?php //可变变量 $a1 = 3; $a2 = 89; $a3 = 32; $a4 = 54; $a5 = 34; $sum = 0; for($i=1; $i<=5; $i++){ $a = "a" . $i; $sum += $$a; } echo $sum; ?>
不知咋地,我的浏览器又正常了,就把这个计算器做了一下,自己瞎写的,结果显示还算正常,就是不知有没有什么写法上的问题,明天再看老师的方法.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>计算器</title> </head> <body> <?php $res = ""; $num1 = ""; $num2 =""; $yunsuanfu = ""; if(!empty($_POST)){ $num1 = $_POST['num1']; $num2 = $_POST['num2']; $yunsuanfu = $_POST['method']; switch($yunsuanfu){ case "+": $res = $num1 + $num2; break; case "-": $res = $num1 - $num2; break; case "*": $res = $num1 * $num2; break; default: $res = $num1 / $num2; break; } } ?> <form method="post"> <input type="text" name="num1" value="<?php echo $num1; ?>"> <select name="method"> <option value="+" <?php if($yunsuanfu=="+"){echo "selected=selected";} ?> >+</option> <option value="-" <?php if($yunsuanfu=="-"){echo "selected=selected";} ?> >-</option> <option value="*" <?php if($yunsuanfu=="*"){echo "selected=selected";} ?> >*</option> <option value="/" <?php if($yunsuanfu=="/"){echo "selected=selected";} ?> >/</option> </select> <input type="text" name="num2" value="<?php echo $num2; ?>"> <input type="submit" value="="> <input type="text" value="<?php echo $res; ?>" > </form> </body> </html>