php中的include和require
一、有什么用? 服务器端包含 (server side include,ssi) 用于创建可在多个页面重复使用的函数、页眉、页脚或元素。包含文件重用了文件,省去了许多工作。
二、怎么用? include ‘filename’;
或
require ‘filename’;
1.php
2.php
在浏览器访问1.php会得到(注意此时1.php和2.php是放在同一个文件夹里的):hello world.
三、include跟require有什么区别? 在错误处理方面:
require 会生成致命错误(e_compile_error)并停止脚本
include 只生成警告(e_warning),并且脚本会继续
请在此时使用:
请在此时使用 require:当文件被应用程序请求时。
请在此时使用 include:当文件不是必需的,且应用程序在文件未找到时应该继续运行时。
版权声明:本文为lshare原创文章,需要转载的请联系我,有问题欢迎评论或私信。