清除回显项 PHP

Clear echoed items PHP

我可以清除所有(已经)回显或打印的项目吗? 我不是在寻找输出缓冲。我正在寻找替代品。

举个例子:

<?php

echo 'a';
print 'b';

The code I need

echo 'c';

The first two statements (echo and print) should not be present in the output
?>

不,无论您写出什么,都会发送到网络服务器,网络服务器再将其发送到浏览器。然而,PHP 中有一个名为 output buffering 的模块(暂时)解耦输出流。

查看 ob_start()ob_end_clean()

<?PHP

ob_start(); // output buffering enabled

// these echos will be buffered in memory, instead of written out as they usually would:
echo 'A';
echo 'B';
echo 'C';

// now we've moved the buffer into `$html` (so that now contains 'ABC'), and we've stopped output buffering.
$html = ob_get_clean();

echo 'D'; // this is being send to the client/webbrowser as usual

echo $html; // now we print the ABC we intercepted earlier


So the client will receive : D A B C