<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会在导入文件以前先检测该文件是否在该页面的其他部分被引用过,如果有,则不重复引用