【发布时间】:2012-10-21 16:08:33
【问题描述】:
一旦我开始使用ob_start() 进行输出缓冲,我想在一个命令中停止输出缓冲并获取其内容(而不将其发送到输出)。 I reviewed the available functions,我对各个功能的理解如下:
clear return send stop
ob_clean x
ob_end_clean x x
ob_end_flush x x
ob_flush x
ob_get_clean x x x // should be called ob_get_end_clean
ob_get_contents x
ob_get_flush x x
据我所知,没有一个函数可以在停止缓冲后返回输出,所以当我想捕获函数的输出时,我必须分 3 步完成:
$output = ob_get_contents();
ob_end_clean();
return $output;
是我遗漏了什么还是有命令停止并一次性返回输出缓冲区?
【问题讨论】:
-
你错过了什么,是的。
ob_get_clean停止,不仅清除,还在缓冲。 -
是的(我认为它应该被称为
ob_get_end_clean) -
或
ob_get_contents_end_clean()?那么简而言之ob_get_clean。也许这有助于记住函数名。