title: echo to page while PHP loads
body: <p>I'm putting together a search engine in php that loops over some directories and echos filtered results as it goes.</p>
  
  <p>My issue is that the echoing, isn't executed until all the searching is finished, causing the page to remain blank until the script is complete.</p>
  
  <p>Is this normal? And if so, how can I get the search results to display at the time the echo is called?</p>
  
  <p>I'll also be eventually writing images in the results to the screen. Instead of echoing everything, could calling a JS document.write function instead speed things up by utilizing both client and server sides simultaneously?</p>
  
  <p><strong>edit:</strong> Here's the code that is iterating. I have a tagging system, but that part is commented out at the moment...</p>
  
  <pre><code>function checkTags($dir, $search){
    global $tag;
    $filesInDir = array_map('strtolower', scandir($dir)); // lower case the files
    $filterOut = array('.','..');
    $filesInDir = array_diff($filesInDir, $filterOut); // get rid of the current '.' and parent '..' values
               //   print_r($filesInDir);
  
  
    foreach($filesInDir as $file) {
      if($file == $tag) {  // found a tag
        echo 'found tag: '.$file.'&lt;br&gt;';
     /*   $tagDir = dirname($tag);
        $tagContents = strtolower(file_get_contents($file).'&lt;br&gt;'.$tagDir); // adding full path to include parent dirs in tag searching
  
        foreach($search as $s){
          if(strpos($tagContents, $s) !== false){ // the tag has a search word
            //getFiles($tagDir);
          }
        }  */
      }
      elseif(is_dir($dir.'/'.$file) !== false) { //is a folder, so try in there
        //print_r($file);
        echo 'found dir: '.htmlspecialchars($file).'&lt;br&gt;';
        checkTags($dir.'\\'.$file, $search);
      }
    }
  }
  </code></pre>
  
  <p>Thanks</p>