2013-04-25 62 views
0

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

+0

哪里输出缓冲 - 包含脚本或主脚本? – 2013-04-25 02:53:25

+0

添加另一层输出缓冲,并使用'ob_get_clean()' – mario 2013-04-25 02:54:01

+0

主脚本调用一个类来设置页面并处理模板。在主页面调用这个类,处理输出,并使用ob_start()// $ template = ob_get_contents(); // ob_clean(); // $ registry-> getObject('template') - > parseOutput(); // $ template = $ registry-> getObject('template') - > getPage() - > getContentToPrint(); // $ template = str_replace(array(“\ r \ n”,“\ n”,“\ r”),'',$ template); // echo $ template; // ob_end_flush(); – RobNHood 2013-04-25 02:56:31

回答

2

试试这个:

ob_start(); 

include 'file.php'; 

$output = ob_get_clean(); 
+0

这是我在决定在课堂上进行处理之前使用的方法。我决定上课的原因是为了更好地组织,处理和存储模板。但是我不知道使用URL而不是file_get_contents的路径将允许php执行。谢谢你的提示。 – RobNHood 2013-04-25 03:15:55

相关问题