Php 将包含的文件内容添加到变量
我正在尝试将包含文件的内容添加到变量中 例如,我有一个名为$form的变量:Php 将包含的文件内容添加到变量,php,Php,我正在尝试将包含文件的内容添加到变量中 例如,我有一个名为$form的变量: $form = 'Hello world'; $form .= include('sidebar.inc.php'); 还有别的办法吗?因为上面提到的方法给我带来了一些问题…您可以使用file\u get\u contents()将其存储在变量中,而不是使用include(): $form = file_get_contents('sidebar.inc.php'); $form = file_get_conten
$form = 'Hello world';
$form .= include('sidebar.inc.php');
还有别的办法吗?因为上面提到的方法给我带来了一些问题…您可以使用
file\u get\u contents()
将其存储在变量中,而不是使用include()
:
$form = file_get_contents('sidebar.inc.php');
$form = file_get_contents('sidebar.inc.php');
在将PHP存储到变量中之前,它不会解析PHP,因此另一个选项是手册中发布的解决方案:
file_get_contents('sidebar.inc.php')不解析php文件。(你的IF-LOOP-ELSE东西)你可以这样做,假设包含的文件在结尾使用了
返回。
$form = file_get_contents('sidebar.inc.php');
ob_start();
include('sidebar.inc.php');
$var = ob_get_flush();