我知道可以包含带变量的php文件.它看起来像这个样本.
include 'http://www.example.com/file.php?foo=1&bar=2';
Run Code Online (Sandbox Code Playgroud)
如何在变量上包含本地文件系统(而不是url)的php文件?像这样的Smth.
include 'file.php?foo=1&bar=2';
Run Code Online (Sandbox Code Playgroud)
可能吗?
更新 我想从索引页面获取变量,并包含从本地系统到内容div的精确变量的文件.像这样
<?php
$foo=$_GET['foo'];
$bar=$_GET['bar'];
?>
<body>
<div id="main">
<div id="content">
<?php
include 'file.php?foo='.$foo.'&bar='.$bar;
?>
</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
变量只在要包含的文件中可用.变量没有文件范围.
所以,如果你这样做
$foo=1; $bar=2;
include 'file.php';
Run Code Online (Sandbox Code Playgroud)
$foo并将$bar在file.php.
上面声明的变量包括语句将在file.php文件中提供.
| 归档时间: |
|
| 查看次数: |
7248 次 |
| 最近记录: |