[英]How to process HTML on server before sending
I want to run a script to process the HTML of a web page just before output - after all PHP and other server side scripts have finished running - adding meta and doing other subtle changes. 我想在输出之前(在所有PHP和其他服务器端脚本完成运行之后)运行脚本来处理网页的HTML,添加元数据并进行其他细微更改。 This is on linux with apache server.
这是在带有apache服务器的linux上。 Is there a standard way to do this?
有标准的方法吗?
I have read about output filters in apache
. 我已经阅读了关于
apache
输出过滤器的信息。 Is this the right way to go? 这是正确的方法吗?
Thanks 谢谢
I think you are talking about Output Buffering : you can tell php to start buffering your output using ob_start();
我认为您在谈论输出缓冲 :您可以告诉php使用
ob_start();
开始缓冲输出ob_start();
then after you finish buffering your content you can send it to the browser as a whole using ob_end_flush();
然后,在您完成内容缓冲后,可以使用
ob_end_flush();
将其作为一个整体发送到浏览器ob_end_flush();
, an example: , 一个例子:
<?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();
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.