将变量放入PHP的include路径中


put variable inside php include path

我试图访问文件夹内的文件,但问题是变量不工作。

我想要的是一旦用户访问网站变量$site和路径应该是'domain.com/inc.index.php'

这是我的代码

$site = $_SERVER['SERVER_NAME'];
include '$site/inc.index.php';
误差

include($site/inc.index.php): failed to open stream: No such file or directory

我发现了同样的问题,但它不适合我。

https://teamtreehouse.com/community/how-do-i-put-a-variable-inside-include-path

你应该使用双引号,而不是单引号:

include "$site/inc.index.php";

单引号不会解析字符串中变量的值,而双引号会。