Blogger Information
Blog 41
fans 2
comment 0
visits 29232
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php之实现九宫格表格和计算器
月光下,遗忘黑暗
Original
1081 people have browsed it

代码块

  1. <?php
  2. /**
  3. * 使用定界符heredoc实现九宫格
  4. */
  5. echo <<<EOF
  6. <table border="1" width="150px" height="150px">
  7. EOF;
  8. for ($i = 0; $i< 9; $i++) {
  9. if ($i%3==0) {
  10. $color = '#'.substr(md5(rand()),0,6);
  11. echo <<<EOF
  12. <tr><td bgcolor="$color">$i</td>
  13. EOF;
  14. } else {
  15. $color = '#'.substr(md5(rand()),0,6);
  16. echo <<<EOF
  17. <td bgcolor="$color">$i</td>
  18. EOF;
  19. }
  20. }
  21. echo <<<EOF
  22. </table>
  23. EOF;
  24. ?>
  25. <!doctype html>
  26. <html lang="en">
  27. <head>
  28. <meta charset="UTF-8">
  29. <meta name="viewport"
  30. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  31. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  32. <title>计算器</title>
  33. </head>
  34. <body>
  35. <form action="" method="post">
  36. <p></p>
  37. <input type="number" name="num1" id="" width="20px"><br>
  38. <input type="radio" value="+" name="operator">+<input type="radio" name="operator" value="-">-<input type="radio" name="operator" value="*">*<input type="radio" name="operator" value="/">/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="submit">=</button>
  39. <br><input type="number" name="num2">
  40. </form>
  41. </body>
  42. </html>
  43. <?php
  44. if (!empty($_POST)) {
  45. switch ($_POST['operator']) {
  46. case "+" :
  47. echo(bcadd($_POST['num1'],$_POST['num2']));
  48. break;
  49. case '-' :
  50. echo(bcsub($_POST['num1'],$_POST['num2']));
  51. break;
  52. case '*' :
  53. echo(bcmul($_POST['num1'],$_POST['num2']));
  54. break;
  55. case '/' :
  56. echo(bcdiv($_POST['num1'],$_POST['num2']));
  57. break;
  58. }
  59. }

效果

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