我希望在输出之前运行一个脚本来处理网页的HTML - 在所有PHP和其他服务器端脚本完成运行之后 - 添加元数据并进行其他微妙的更改。这是在linux上使用apache服务器。有没有标准的方法来做到这一点?
我已阅读apache
中有关输出过滤器的内容。这是正确的方法吗?
由于
答案 0 :(得分:1)
我认为你在谈论Output Buffering:
您可以告诉php使用ob_start();
开始缓冲输出,然后在完成缓冲内容后,您可以使用ob_end_flush();
将其作为整体发送到浏览器,例如:
<?php
// start output buffering at the top of our script with this simple command
ob_start();
?>
<html>
<body>
<p>Hello world!</p>
<?php echo "<p>Hello again!</p>"; ?>
</body>
</html>
<?php
// end output buffering and send our HTML to the browser as a whole
ob_end_flush();
?>