php——學習筆記,include,require,include_once,require_once引用文件時的異同

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>應用include語句引用外部文件</title>
</head>
<body>
<table width="975" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td><?php include("top.php");?></td>
  </tr>
  <tr>
    <td><?php include("main.php");?></td>
  </tr>
  <tr>

    <td><?php

 include("bottom.php");

?></td>

  </tr>
</table>
</body>

</html>

當php解析器看到include時,會去找這個文件(如果在同一文件內就不需要輸入路徑),然後會把這個文件內的所有內容拉到本文件中

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>應用require()函數包含文件</title>
</head>
<body>
<table width="975" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td><?php require("top.php");?></td>
  </tr>
</table>
</body>
</html>

唉?好像require也是這樣哦,那include和require有什麼區別呢,在沒有找到要調用的文件時,require會輸出錯誤信息並且會終止腳本的處理,而include會輸出警告,並不終止腳本的處理;

require語句調用文件時,只要程序一執行,就會立刻調用外部文件,而通過include只有程序執行到該文件時纔會調用外部文件。


那include_once,require_once會在導入文件以前先檢測該文件是否在該頁面的其他部分被引用過,如果有,則不重複引用

發佈了44 篇原創文章 · 獲贊 1 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章