There's simply no way for you to do it.
The proper method, is to process all the values before the HTML.
It's called separation of logic and view.
I'm guessing you have something like
<body><?php include 'content.php' ?></body>
In which case there's not really an easy solution, except to rewrite the logic so it's processed (and hold the data in a variable) before the <html>. Then within content.php, you would simply output the processed variable instead of doing the logic there. This is the essence of a template system.