每当我们包含要求使用php之类的某些文件时
require ('links.php');或include ('links.php');
发生以下两种情况之一
例
可以说有一个文件file.php和下面的代码
echo"my things";
?>
我们将其包含在
------
------
echo"about to include file";
include ('file.php')
?>
------
------
场景1:
包括的文件的代码插入到parent container文件的PHP代码中,然后处理完整的代码并生成HTML result。
意思是,首先将此代码放在第一个
------
------
echo"about to include file";
echo"my things";
?>
?>
------
------
然后处理
场景2:
首先处理包含的文件,然后插入结果
意味着首先将处理包含文件并获得结果
mythings
然后将其放置在parent container includer代码中,然后对该代码进行处理
------
------
echo"about to include file";
my things
?>
------
------
现在它将被处理
您到底要问什么? 问题是什么?
p.s SCENARIO 1可能导致语法错误,SCENARIO 2可能导致变量问题以及许多其他逻辑和条件问题
@ sarfraz :没问题...只需要解释下面的内容
好吧,仅使用" include"这个名称可能并不容易理解。
所以-当您这样做时会发生什么
echo"including now...";
include"myFile.php";
echo"blah";
?>
然后基本上会变成这样:
echo"including now...";
?>
CONTENTS OF myFile.php HERE
echo"blah";
?>
意味着在您的示例中,它看起来像这样:
echo"about to include file";
?>
echo"my things";
?>
?>
如果它是如此简单,那么我就无需发布此问题。 有什么想法吗?
这是场景一。
另请注意,require仅将代码放入一次! 所以:
echo"about to include file";
require ('file.php');
require ('file.php');
require ('file.php');
echo"included the file";
?>
将产生:
echo"about to include file";
?><?php
echo"my things";
?>
echo"included the file";
?>
而:
echo"about to include file";
include ('file.php');
include ('file.php');
include ('file.php');
echo"included the file";
?>
将产生:
echo"about to include file";
?><?php
echo"my things";
?>
echo"my things";
?>
echo"my things";
?>
echo"included the file";
?>
这是场景一。 include是在该行代码中"注入"代码的简单机制。
作为历史的花哨,在PHP 4.1之前,即使语句处于从未执行过的块或条件中,也要处理include。 除此之外,PHP没有任何适合您的方案2的东西。