One way that I would do it is instead of printing out the HTML while the script is running, store it all into a variable. Then, at the very end of the script, print out the variable, and do whatever else you wanted to with it. That way, the variable will have all your HTML source code in it.