如何将php文件导入变量?

时间:2023-01-20 01:13:27

Does it possible to execute php file and store its output into some variable?

是否可以执行php文件并将其输出存储到某个变量中?

For example i have one global template, then i need to process subtemplates, and afterall i need to insert that subtemplate output into global template block.

例如,我有一个全局模板,然后我需要处理子模板,毕竟我需要将该子模板输出插入到全局模板块中。

How can i do it ?

我该怎么做 ?

1 个解决方案

#1


You can use the output control functions, buffer the output with ob_start and retrieve it with ob_get_contents:

您可以使用输出控制函数,使用ob_start缓冲输出并使用ob_get_contents检索它:

ob_start();
func();
$output = ob_get_contents();
ob_end_clean();

#1


You can use the output control functions, buffer the output with ob_start and retrieve it with ob_get_contents:

您可以使用输出控制函数,使用ob_start缓冲输出并使用ob_get_contents检索它:

ob_start();
func();
$output = ob_get_contents();
ob_end_clean();