![](/img/trans.png)
[英]How can I include / exclude a part of an included PHP file based on the file I am including it in?
[英]PHP How to exclude a file which is included in the file I am including?
假设我想包含header.php
文件,而header.php
已经包含另一个包含functions.php
的文件。 如果在我的index.php
中包括header.php
那么自然functions.php
。php 也会被包括在内。 但是,如果由于某些特定原因我想打破联合并排除functions.php
而包括header.php
怎么办? 这可能吗?
由于经过大量搜索我找不到本地 PHP function 我想出的解决方法是:
if(basename($_SERVER['PHP_SELF']) != 'page-name.php'){
include('functions.php');
}
使用此代码functions.php
。php 将包含在 header.php 的所有页面中,仅page-name.php
header.php
除外
您可以更改为:
include_once 'functions.php';
所以它只会包含一次,即使 Header.php 和 Index.php 有它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.