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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值