The PHP output buffering


The PHP output buffering will save all the server outputs ( html and php prints) to a string variable.

So to start buffering, use ob_start(); this will keep saved any output.
Then you use $variable = ob_get_clean(); to stop buffering, and copy the buffer content to the variable.

Here are few samples of the use of ob_start() and ob_get_clean()



Hello world, link
Content



Now the content of the variable $var should be:

Hello word, link
Content


Another example (with php outputs buffered)


Hello world,
Thank you.



And this will be the content of $var:
Hello world, My Website
Thank you.

That's all !

No comments:

Post a Comment