开发者

PHP ob_start() question

开发者 https://www.devze.com 2023-01-23 00:00 出处:网络
Am I allowed to have two or more ob_start();开发者_StackOverflow中文版 in my php files if so what is the proper way to end one ob_start(); and start another?From the manual:

Am I allowed to have two or more ob_start();开发者_StackOverflow中文版 in my php files if so what is the proper way to end one ob_start(); and start another?


From the manual:

Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. Just make sure that you call ob_end_flush() the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order.

In addition to stacking (nesting), you can have separate blocks in sequence.

<?
ob_start();
echo "Foo";
ob_end_flush(); // outputs buffer contents and turns off output buffering

ob_start();
echo "Bar";
ob_end_flush();
?>


You are allowed to do more than one ob_start() on a page. You end ob_start() with ob_end_clean().

ob_start();
$postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
ob_end_clean();
echo $postOutput;
0

精彩评论

暂无评论...
验证码 换一张
取 消