Is there any way for all my PHP and/or HTML file output to be “filtered” before being displayed in the browser? I figured that I could pass it through a global function before it is displayed but I’m stuck on the implementation. Please help.
If there is a better way to achieve the same result, I’d be happy to know.
Thanks.
Check out ob_start which lets you pass a callback handler for post-processing your script output.
For example, PHP includes a built-in callback ob_gzhandler for use in compressing the output:
Here’s a fuller example illustrating how you might tidy your HTML with the tidy extension:
If you wanted to ensure all your PHP scripts used the same filter without including it directly, check out the auto_prepend_file configuration directive.