您可以通过使用 ExtFilterDefine 和 SetOutputFilter 创建自定义输出过滤器并运行 PHP 脚本来执行此操作,该脚本读取 stdin:// 然后插入所需的代码并输出它。查看http://httpd.apache.org/docs/2.2/mod/mod_ext_filter.html开始使用。
如果您只关心 PHP 输出而不是静态 HTML 文件,您可以使用 auto_prepend_file 运行一个调用 的脚本ob_start(),并使用 auto_append_file 运行一个脚本,该脚本调用$html = ob_get_clean()代码并将其插入到 $html 中,然后再回显它。