PHP:include\require行为
每当我们包含\需要使用php之类的文件时PHP:include\require行为,php,include,require,Php,Include,Require,每当我们包含\需要使用php之类的文件时 require('links.php')或包含('links.php') 以下两种情况中的哪一种会发生 示例 假设有一个filefile.php和以下代码 <?php echo "my things"; ?> <br /> 我们把它包括在 ------ ------ <?php echo "about to include file"; include ('file.php') ?> ------ ------
require('links.php')
或包含('links.php')代码>
以下两种情况中的哪一种会发生
示例
假设有一个filefile.php
和以下代码
<?php
echo "my things";
?>
<br />
我们把它包括在
------
------
<?php
echo "about to include file";
include ('file.php')
?>
------
------
------
------
------
------
场景1:
包含文件的代码被插入到parents\container files PHP代码中,然后处理完整的代码并生成HTML\result
意思是,先把这个代码放在第一位
------
------
<?php
echo "about to include file";
<?php
echo "my things";
?>
<br />
?>
------
------
------
------
?>
------
------
然后处理
场景2:
首先处理包含的文件,然后插入结果
这意味着首先将处理include文件并获得结果
mythings<br/>
mythings
然后将其放在父\container\includer代码中,然后对该代码进行整理处理
------
------
<?php
echo "about to include file";
my things<br />
?>
------
------
------
------
------
------
现在它将被处理这是场景一include
是在该行代码中“注入”代码的简单机制
在PHP4.1之前的历史上,即使语句处于从未执行过的块或条件中,include
s也会被处理。除此之外,PHP没有任何可以接近场景2的功能。这是场景1include
是在该行代码中“注入”代码的简单机制
在PHP4.1之前的历史上,即使语句处于从未执行过的块或条件中,include
s也会被处理。除此之外,PHP没有任何与场景2相近的功能。好吧,仅使用“include”名称可能不容易理解
那么-当你这样做时会发生什么
<?php
echo "including now...";
include "myFile.php";
echo "blah";
?>
然后基本上会变成这样:
<?php
echo "including now...";
?>
CONTENTS OF myFile.php HERE
<?php
echo "blah";
?>
<?php
echo "about to include file";
?>
<?php
echo "my things";
?>
<br />
<?php
?>
这里是myFile.php的内容
这意味着在您的示例中,它将如下所示:
<?php
echo "including now...";
?>
CONTENTS OF myFile.php HERE
<?php
echo "blah";
?>
<?php
echo "about to include file";
?>
<?php
echo "my things";
?>
<br />
<?php
?>
好吧,仅仅使用“包含”名称可能不容易理解
那么-当你这样做时会发生什么
<?php
echo "including now...";
include "myFile.php";
echo "blah";
?>
然后基本上会变成这样:
<?php
echo "including now...";
?>
CONTENTS OF myFile.php HERE
<?php
echo "blah";
?>
<?php
echo "about to include file";
?>
<?php
echo "my things";
?>
<br />
<?php
?>
这里是myFile.php的内容
这意味着在您的示例中,它将如下所示:
<?php
echo "including now...";
?>
CONTENTS OF myFile.php HERE
<?php
echo "blah";
?>
<?php
echo "about to include file";
?>
<?php
echo "my things";
?>
<br />
<?php
?>
这是场景一
还要注意,require
只会输入一次代码!因此:
<?php
echo "about to include file";
require ('file.php');
require ('file.php');
require ('file.php');
echo "included the file";
?>
将产生:
<?php
echo "about to include file";
?><?php
echo "my things";
?>
<br /><?
echo "included the file";
?>
<?php
echo "about to include file";
?><?php
echo "my things";
?>
<br /><?php
echo "my things";
?>
<br /><?php
echo "my things";
?>
<br /><?php
echo "included the file";
?>
鉴于:
<?php
echo "about to include file";
include ('file.php');
include ('file.php');
include ('file.php');
echo "included the file";
?>
将产生:
<?php
echo "about to include file";
?><?php
echo "my things";
?>
<br /><?
echo "included the file";
?>
<?php
echo "about to include file";
?><?php
echo "my things";
?>
<br /><?php
echo "my things";
?>
<br /><?php
echo "my things";
?>
<br /><?php
echo "included the file";
?>
这是场景一
还要注意,require
只会输入一次代码!因此:
<?php
echo "about to include file";
require ('file.php');
require ('file.php');
require ('file.php');
echo "included the file";
?>
将产生:
<?php
echo "about to include file";
?><?php
echo "my things";
?>
<br /><?
echo "included the file";
?>
<?php
echo "about to include file";
?><?php
echo "my things";
?>
<br /><?php
echo "my things";
?>
<br /><?php
echo "my things";
?>
<br /><?php
echo "included the file";
?>
鉴于:
<?php
echo "about to include file";
include ('file.php');
include ('file.php');
include ('file.php');
echo "included the file";
?>
将产生:
<?php
echo "about to include file";
?><?php
echo "my things";
?>
<br /><?
echo "included the file";
?>
<?php
echo "about to include file";
?><?php
echo "my things";
?>
<br /><?php
echo "my things";
?>
<br /><?php
echo "my things";
?>
<br /><?php
echo "included the file";
?>
您的问题到底是什么?问题是什么?p.s方案1可能导致语法错误,方案2可能导致变量问题和许多其他逻辑和条件问题@sarfraz:
没有问题。。。只是想解释一下到底发生了什么你的问题到底是什么?问题是什么?p.s方案1可能导致语法错误,方案2可能导致变量问题和许多其他逻辑和条件问题@sarfraz:
没有问题。。。只要解释一下下面发生了什么,我就不需要发帖了。有什么想法吗?如果这么简单,我就不需要发帖了。有什么想法吗?