Blogger Information
Blog 9
fans 0
comment 0
visits 7982
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
require与include加载示例
若是梦终会醒
Original
826 people have browsed it

1.demo.php文件内容

  1. <?php
  2. $porm = $_POST['load'] ?? null;
  3. echo $porm;
  4. $file = 'load.php';
  5. ?>
  6. <!DOCTYPE html>
  7. <html lang="zh-CN">
  8. <head>
  9. <meta charset="UTF-8">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <title>加载</title>
  12. <style>
  13. * {
  14. margin: 0;
  15. padding: 0;
  16. }
  17. div {
  18. width: 1000px;
  19. height: 900px;
  20. margin: 0 auto;
  21. }
  22. div>div {
  23. width: 100%;
  24. height: 33.3%;
  25. }
  26. .btn {
  27. position: fixed;
  28. top: 100px;
  29. left: 50px;
  30. font-size: 18px;
  31. }
  32. h3 {
  33. color: red;
  34. }
  35. </style>
  36. </head>
  37. <body>
  38. <div>
  39. <?
  40. switch (true):
  41. case $porm < 2:
  42. if (file_exists($file) && is_file($file) && $porm) : //条件加载的条件
  43. echo '<h3>条件存在加载</h3>';
  44. include "{$file}";
  45. else :
  46. echo '<h3>条件不存在加载</h3>';
  47. include 'default.php';
  48. endif;
  49. break;
  50. case $porm < 4:
  51. if ($porm == 2) :
  52. echo '<h3>不去重加载</h3>';
  53. include "{$file}";
  54. include "{$file}";
  55. include "{$file}";
  56. else :
  57. echo '<h3>去重加载</h3>';
  58. include_once "{$file}";
  59. include_once "{$file}";
  60. include_once "{$file}";
  61. endif;
  62. break;
  63. case $porm < 6:
  64. if ($porm == 4) :
  65. echo '<h3>强制加载</h3>';
  66. require "{$file}";
  67. require "{$file}";
  68. require "{$file}";
  69. else :
  70. echo '<h3>强制去重加载</h3>';
  71. require_once "{$file}";
  72. require_once "{$file}";
  73. require_once "{$file}";
  74. endif;
  75. break;
  76. case $porm < 8:
  77. if ($porm == 6) :
  78. echo '<h3>include和require加载区别之include加载</h3>';
  79. include "{$file}s";
  80. else :
  81. echo '<h3>include和require加载区别之require加载</h3>';
  82. require "{$files}s";
  83. endif;
  84. break;
  85. endswitch;
  86. ?>
  87. </div>
  88. <section class="btn">
  89. <form action="demo.php" method="post">
  90. <select name="load" id="" style='height: 50px; font-size: 16px; background: pink;'>
  91. <option value="0">条件不存在</option>
  92. <option value="1" <? echo $porm == 1 ? 'selected' : null; ?>>条件存在</option>
  93. <option value="2" <? echo $porm == 2 ? 'selected' : null; ?>>不去重加载</option>
  94. <option value="3" <? echo $porm == 3 ? 'selected' : null; ?>>去重加载</option>
  95. <option value="4" <? echo $porm == 4 ? 'selected' : null; ?>>强制加载</option>
  96. <option value="5" <? echo $porm == 5 ? 'selected' : null; ?>>强制去重加载</option>
  97. <option value="6" <? echo $porm == 6 ? 'selected' : null; ?>>include和require加载区别之include加载</option>
  98. <option value="7" <? echo $porm == 7 ? 'selected' : null; ?>>include和require加载区别之require加载</option>
  99. </select>
  100. <input type="submit" value="确定">
  101. </form>
  102. </section>
  103. </body>
  104. </html>

2.load.php文件内容

  1. <?php
  2. $str = <<< DIV
  3. <div class="ifLoad" style="background-color: pink;"></div>
  4. <div class="quzLoad" style="background-color: yellowgreen;"></div>
  5. DIV;
  6. echo $str;

3.default.php文件内容

  1. <?php
  2. $str = <<< 'DIV'
  3. <div class="quzLoad" style="background-color: yellowgreen;"></div>
  4. <div class="ifLoad" style="background-color: pink;"></div>
  5. DIV;
  6. echo $str;

演示效果图:
1.条件不存在加载

2.条件存在加载

3.不去重加载

4.去重加载

5.强制加载

6.强制去重加载

7.include和require加载区别之include加载

8.include和require加载区别之require加载

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