将Include分配给字符串变量PHP

时间:2013-04-25 02:51:36

标签: php include

我有模板文件,我需要进一步处理,所以想使用include不使用file_get_contents将其分配给字符串变量。原因是因为最终输出是通过ob缓冲的,并且包含需要执行的php。如果我使用file_get_contents它不会执行。问题是如果我使用$ output = include'file.php'它打印输出而不分配。

1 个答案:

答案 0 :(得分:2)

试试这个:

ob_start();

include 'file.php';

$output = ob_get_clean();