I don't think what you have in mind is possible. The PHP Apache 2
filter executes code embedded in the output stream (with limitation).
It wasn't designed to let a script filter the output stream. You can
get around that through the use of an auto-prepend script and output
buffering. But why use a hack when there're more orthodox way of doing
things?