PHP flush, sleep, and browsers…

If anything else doesn’t work, try this sample code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
<?php
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
for ($i = 0; $i &lt; ob_get_level(); $i++) { ob_end_flush(); }
ob_implicit_flush(1);

// All you need is 256 spaces first
echo str_repeat(" ", 256); ob_flush();
for($i=0;$i&lt;10;$i++)
{
   echo $i,' ';
   ob_flush();
   sleep(1);
}

Clean multiple new lines in a text

/**
 * Clean duplicates new line
 *
 */
  function cleanNewLine($text)  {
    $newLine = "\r\n";
    $strRes = '';

    $posNewLine = strpos($text, $newLine);
    if ($posNewLine===false) {
      $strRes = $text;

    } else {
      $startText = substr($text, 0, $posNewLine+2);
      $endText = substr($text, $posNewLine+2);
      $strRes .= $startText."";

      // Remove duplicate new line if exists
      $posNewLine = strpos($endText, $newLine);
      while($posNewLine===0) {
        $endText = substr($endText, $posNewLine+2);
        $posNewLine = strpos($endText, $newLine);
      }

      $strRes .= self::cleanNewLine($endText);
    }

    return $strRes;
  }