Blogger Information
Blog 19
fans 1
comment 0
visits 12266
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
练习使用定界符和写一个计算器
▽空城旧梦
Original
399 people have browsed it

使用定界符

  1. <?php
  2. $color1="red";
  3. var_dump($color1);
  4. echo <<<EOF
  5. <!DOCTYPE html>
  6. <html lang="zh-CN">
  7. <head>
  8. <meta charset="UTF-8" />
  9. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  11. <title>九宫格</title>
  12. </head>
  13. <style type="text/css">
  14. .boxfather {
  15. display: flex;
  16. flex-wrap: wrap;
  17. width: 150px;
  18. }
  19. .box {
  20. width: 50px;
  21. height: 50px;
  22. box-sizing: border-box;
  23. border: 1px solid black;
  24. }
  25. </style>
  26. <body>
  27. <body>
  28. <div class="boxfather">
  29. <div class="box" style="background-color:{$color1}"></div>
  30. <div class="box" style="background-color:{$color1}"></div>
  31. <div class="box" style="background-color:{$color1}"></div>
  32. <div class="box" style="background-color:{$color1}"></div>
  33. <div class="box" style="background-color:{$color1}"></div>
  34. <div class="box" style="background-color:{$color1}"></div>
  35. <div class="box" style="background-color:{$color1}"></div>
  36. <div class="box" style="background-color:{$color1}"></div>
  37. <div class="box" style="background-color:{$color1}"></div>
  38. </div>
  39. </body>
  40. </body>
  41. </html>
  42. EOF;
  43. ?>

计算器

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>计算器</title>
  8. </head>
  9. <body>
  10. <?php
  11. error_reporting(E_ALL & ~E_NOTICE);
  12. if(isset($_POST['sub']))
  13. {
  14. if($_POST['opt'] == '/' && $_POST['num2'] == 0 || $_POST['opt'] == '%' && $_POST['num2'] == 0) $mess = "<span style='color:red;'>oops~除数不能为0</span>";
  15. }
  16. ?>
  17. <table border="1">
  18. <form action="" method="POST">
  19. <tr>
  20. <th colspan="3">计算器</th>
  21. </tr>
  22. <tr>
  23. <td><input type="number" name="num1" required></td>
  24. <td>
  25. <select name="opt">
  26. <option value="+">+</option>
  27. <option value="-">-</option>
  28. <option value="*">*</option>
  29. <option value="/">/</option>
  30. </select>
  31. </td>
  32. <td><input type="number" name="num2" required></td>
  33. </tr>
  34. <tr>
  35. <td colspan="3" align="center">
  36. <input type="submit" name="sub" value="计算">
  37. </td>
  38. </tr>
  39. </form>
  40. </table>
  41. <?php
  42. if(!$mess):
  43. switch($_POST['opt']):
  44. case "+":
  45. $sum = (int)$_POST['num1'] + (int)$_POST['num2'];break;
  46. case "-":
  47. $sum = (int)$_POST['num1'] - (int)$_POST['num2'];break;
  48. case "*":
  49. $sum = (int)$_POST['num1'] * (int)$_POST['num2'];break;
  50. case "/":
  51. $sum = (int)$_POST['num1'] / (int)$_POST['num2'];break;
  52. case "%":
  53. $sum = (int)$_POST['num1'] % (int)$_POST['num2'];break;
  54. endswitch;
  55. $res = "计算结果:{$_POST['num1']} {$_POST['opt']} {$_POST['num2']} = {$sum}";
  56. echo "<span style='color:green;'>{$res}</span>";
  57. else:
  58. echo $mess;
  59. endif;
  60. ?>
  61. </body>
  62. </html>
Correcting teacher:灭绝师太灭绝师太

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post