1

Is there anything i am doing wrong in the following code.

Ob_start should buffer the output right and it should not print it before you flush. But it is doing that

<?php
echo "Hello World!";
ob_start();
for ($i=0; $i < 100; $i++ ){
    echo "I am fine </br>";
}
?>

I am getting the output "i am fine"

indianwebdevil
  • 4,879
  • 7
  • 37
  • 51

2 Answers2

4

It's flushed when the script ends, so of course you will still get the output, it just won't be sent while the script is still running.

Alasdair
  • 13,348
  • 18
  • 82
  • 138
3

You should do something with the buffer at the end of your script.

E.g. get the contents with ob_get_contents() and clear it with ob_end_clean(), otherwise it is flushed at the end.

Kleist
  • 7,785
  • 1
  • 26
  • 30