如何将参数传递给包含文件?我尝试了以下但它不起作用.
包括"myfile.php?var = 123";
在myfile.php中,我尝试使用$ _GET ["var"]检索参数.
include "myfile.php?var=123";不管用.PHP搜索具有此确切名称的文件,但不解析该参数
为此我也这样做了:
include "http://MyGreatSite.com/myfile.php?var=123";但它也不起作用.
任何提示?谢谢.
又快又脏
$var = 123;
include "myfile.php";
Run Code Online (Sandbox Code Playgroud)
在 myfile 中只需使用“$var”
相同但没有全局变量:
function use_my_file($param) {
$var = $param;
include "myfile.php";
}
Run Code Online (Sandbox Code Playgroud)
等等,您是否试图包含myfile.php 的结果,而不是它的 php 代码?那么请考虑以下内容
$var = 123;
readfile("http://MyGreatSite.com/myfile.php?var=$var"); //requires allow_url_fopen=on in php.ini
Run Code Online (Sandbox Code Playgroud)
虚拟也可能有效
将包含文件的内容包装在函数(或函数)中.这样你就可以做到
include "myfile.php";
myFileFunction($var1, $var2);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10805 次 |
| 最近记录: |