如何使用 include straight in define in php

how to use include straight in define in php

我想在 php

的定义中直接使用 include

例如

<?php define('panel' , 'include "../panel/admin.php";'); //in a saperate php page ?>

并包含此文件

现在我想使用

<?php panel ?> //in another page

你不能在 define

中使用 include()

你必须这样做

<?php define("panel" , "../panel/admin.php"); ?>

然后包含它

<?php 

include(panel);

 ?>

正确。

但是,您可以通过以下方式对现有代码执行相同的操作。

 define('panel' , 'include "/panel/admin.php";'); 

 eval(panel); // eval — Evaluate a string as PHP code

希望对您有所帮助:)