在PHP中,include()到底如何工作? [英] In PHP, how does include() exactly work?

查看:60
本文介绍了在PHP中,include()到底如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

include('./code.php');如何工作?我了解这等同于将代码直接粘贴"到包含发生的位置,但是,例如:

How does include('./code.php'); work? I understand it is the equivalent of having the code "pasted" directly where the include occurs, but, for example:

如果我有两个页面,分别是page1.phppage2.php,我需要在./code.php中操纵不同的变量和函数,include()是否创建./code.php的副本,或者实质上是链接回到实际页面./code.php?

If I have two pages, page1.php and page2.php, of which I would need to manipulate different variables and functions in ./code.php, does include() create a copy of ./code.php, or does it essentially link back to the actual page ./code.php?

推荐答案

请参见手册.

如果您include文本文件,它将在文档中显示为文本.

If you include a text file, it will show as text in the document.

include 的行为类似于复制粘贴:

include does not behave like copy-paste:

test.php

<?php
echo '**';
$test = 'test';
include 'test.txt';
echo '**';
?>

test.txt

echo $test;

上面的示例将输出:

**echo $test;**

如果要包含PHP文件,则仍需要具有PHP标签<?php?>.

If you are going to include PHP files, you still need to have the PHP tags <?php and ?>.

此外,通常不会在include之后加上括号,如下所示:

Also, normally parentheses are not put after include, like this:

include 'test.php';

这篇关于在PHP中,include()到底如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆