[英]PHP only include file if variable is called
我认为最好给出一个我要解决的问题的示例,而不是发布我的代码。 (如果您仍然想要代码,请告诉我)。
我正在尝试创建一个文件夹和一个index.php文件,其中包含多个具有很大差异的不同站点。 我有本地主机指向wwwroot文件夹中的Development文件夹。 在dev文件夹中,我有一个index.php,一个全局include文件夹以及更多文件夹中的多个mini php站点。
我需要为每个站点设置指向包含文件的变量。 例:
$html5 = include '/global-includes/global-html5standard.php';
$email = include '/global-includes/global-emailtemp.php';
根据我想在索引上看到的站点,我将调用特定变量。
echo $html5;
同时将其他变量注释掉。
//echo $email;
问题是无论如何都包含对内容的提取。 我想使其仅在调用时才拉入。
您可以将变量更改为仅路径名。
$html5 = '/global-includes/global-html5standard.php';
然后包括变量。 而不是echo $html5;
您将使用include( $html5 );
您可能要改用函数 。
function email() {
include('/global-includes/global-emailtemp.php');
}
function html5() {
include('/global-includes/global-html5standard.php');
}
您可能还想使用include_once(),因此无论调用多少次,文件都只会被包含一次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.