I have template files which I need to further process so would like to assign it to a string variable using an include not using file_get_contents. The reason for this is because the final output is buffered through ob and contains php which needs to execute. If I use file_get_contents it wont execute. Problem is if I use $output = include 'file.php' it prints output without assigning.
1 Answer
Try this:
ob_start();
include 'file.php';
$output = ob_get_clean();
1 Comment
RobNHood
That was the method I was using before I decided to do the processing in a class. Reason I decided to do the class was to better organize, process and store the templates. However I did not know that using a URL instead of path for file_get_contents would allow the php to execute. Thanks for the tip.
ob_get_clean()CORRUPTis exactly what you want, but just to note, if you use a url infile_get_contents()instead of a filepath, the php should execute.