将值传递给php中的包含文件 [英] Pass value to an include file in php

查看:100
本文介绍了将值传递给php中的包含文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将参数传递到包含文件中?我尝试了以下操作,但不起作用.

How do you pass a parameter into an include file? I tried the following but it doesn't work.

包括"myfile.php?var = 123";

include "myfile.php?var=123";

在myfile.php中,我尝试使用$ _GET ["var"]检索参数.

and in myfile.php, I try to retrieve the parameter using $_GET["var"].

include "myfile.php?var=123";将不起作用. PHP搜索具有此确切名称的文件,但不解析参数

include "myfile.php?var=123"; will not work. PHP searches for a file with this exact name and does not parse the parameter

为此,我也这样做了:

include "http://MyGreatSite.com/myfile.php?var=123";,但它也不起作用.

有任何提示吗?谢谢.

推荐答案

将所包含文件的内容包装在一个或多个函数中.这样您就可以做到

Wrap the contents of the included file in a function (or functions). That way you can just do

include "myfile.php";
myFileFunction($var1, $var2);

这篇关于将值传递给php中的包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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