Jump to content

[SOLVED] ob_implicit_flush(true);


StefanRSA

Recommended Posts

Hi,

 

Have the following code:

<?php
ob_implicit_flush(true);
for($i=0;$i<5;$i++)
{
$dis=<<<DIS
<div style="width:200px; background-color:lime;border:1px; text-align:center;text-decoration:blink;">
$i
</div>
DIS;
echo $dis;

sleep(5);
//flush();
}
?>

 

This gives me flashing 0 to 4 in seperate line breaks.

How do I replace the 0 to "Some text A"

1 to "Some text B"

2 to "Some text C" and so on?

 

Please can anybody help me....

Link to comment
https://forums.phpfreaks.com/topic/152941-solved-ob_implicit_flushtrue/
Share on other sites

This is one way of doing it...

<?php
ob_implicit_flush(true);
$arrLetters=range('A','F');
for ($i=0;$i<5;$i++) {
  echo '<div style="width:200px; background-color:lime;border:1px; text-align:center;text-decoration:blink;">Some text '.$arrLetters[$i].'</div>';
  sleep(5);
//flush();
}
?>

This is another way...

<?php
ob_implicit_flush(true);
$arrLetters=range('A','F');
$arrLetters='Some text '.$arrLetters;
for ($i=0;$i<5;$i++) {
  echo '<div style="width:200px; background-color:lime;border:1px; text-align:center;text-decoration:blink;">'.$arrLetters[$i].'</div>';
  sleep(5);
//flush();
}
?>

Thanks Yesideez,

 

Ha Ha! This is a typical case of getting exactly what a person is asking for lol!

I should actually ask my question correctly!

 

With

<?php
ob_implicit_flush(true);
$arrLetters=range('A','F');
for ($i=0;$i<5;$i++) {
  echo '<div style="width:200px; background-color:lime;border:1px; text-align:center;text-decoration:blink;">Some text '.$arrLetters[$i].'</div>';
  sleep(5);
//flush();
}
?>

i get "Some Text A

Some Text B and so on...

 

With

<?php
ob_implicit_flush(true);
$arrLetters=range('A','F');
$arrLetters='Some text '.$arrLetters;
for ($i=0;$i<5;$i++) {
  echo '<div style="width:200px; background-color:lime;border:1px; text-align:center;text-decoration:blink;">'.$arrLetters[$i].'</div>';
  sleep(5);
//flush();
}
?>

i get

S

o

m

e.....

 

I am actually trying to do this.....:

"Verifying Data"

"Verifying Dates"

"Connecting to DB"

"Collecting Info"

"Verifying Results"

 

That is what I meant by "Some Text A" "Some Text B" and so on.

Do I miss anything?

 

 

Major LOL with a bit of ROFL ;)

 

You can set up an array manually like this...

<?php
ob_implicit_flush(true);
$arrText=array('Verifying Data','Verifying Dates','Connecting to DB');
for ($i=0;$i<5;$i++) {
  echo '<div style="width:200px; background-color:lime;border:1px; text-align:center;text-decoration:blink;">'.$arrText[$i].'</div>';
  sleep(5);
//flush();
}
?>

 

I know that's still pretty much exactly the same but if you're wanting PHP to change them in order with only one item displayed at a time - it can't be done. The server parses the PHP code and throws it to the browser when finished.

 

If you want this to update you'd need to use Javascript but you wouldn't be able to match this up with anything PHP was doing.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.