PDA

View Full Version : PHP output to browser.



muneeba9071
03-19-2011, 04:25 PM
Hi,

Take this sample loop:



for($i = 1; $i <= 4; $i++) {
print $i."<br>";
sleep(2);
}


When you run the above, it will output all numbers at once. How we can print each number to the browser and wait 2 seconds, then print the other one?

tangoforce
03-19-2011, 04:29 PM
You can try using flush() but be warned it isn't guaranteed to work. Thats because of the way http works.

mlseim
03-20-2011, 05:04 AM
You'll need to use Javascripting for that.

oesxyl
03-20-2011, 05:10 AM
Hi,

Take this sample loop:



for($i = 1; $i <= 4; $i++) {
print $i."<br>";
sleep(2);
}


When you run the above, it will output all numbers at once. How we can print each number to the browser and wait 2 seconds, then print the other one?

http://www.php.net/manual/en/function.flush.php#85382

read all the page, in many cases will not work, the best solution was suggested by mlseim, javascript
best regards