PHP question ob_start ()

I am allowed to have two or more ob_start(); in my php files, if so, what is the correct way to end one ob_start(); and run another?

+4
source share
2 answers

From the manual:

Output buffers are stacked, that is, you can call ob_start (), while the other ob_start () is active. Just make sure you call ob_end_flush () the appropriate number of times. If multiple output callback functions are active, the output is filtered sequentially through each of them into the nesting order.

In addition to stacking (nesting), you can have individual 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(); ?> 
+6
source

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

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

All Articles