php输出到页面中间

For my website I have a template file that is included in all files and contains functions for outputting all of the consistent elements across all pages on my site, including a footer.

I am trying to have a page that will load to the point of having all of this content in place and then go back and add the output from a call to system in the content element.

Does anybody have any ideas how this could be done? I can get it to output the result of system the way I need, but the footer is always added after the last line from this call...

EDIT:

Here's an example of what I am trying to do:

<?php
OutputHeader();

OutputContentLineByLine();

OutputFooter();
?>

Where OutputHeader puts the page header, OutputFooter puts the page footer and OutputContentLineByLine calls an external program with system and outputs the result line by line. The footer should be output before the content but show before the content.