PHP加载时回显到页面

Joh*_*ohn 0 php echo

我正在整理一个搜索引擎在php中循环一些目录和回声过滤结果.

我的问题是,在所有搜索完成之前不会执行回显,导致页面保持空白,直到脚本完成.

这是正常的吗?如果是这样,我怎样才能在调用回声时显示搜索结果?

我也将最终将结果中的图像写入屏幕.可以通过同时利用客户端和服务器端来调用JS document.write函数来代替回应所有内容吗?

编辑:这是迭代的代码.我有一个标记系统,但此部分已被注释掉了...

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.'<br>';
   /*   $tagDir = dirname($tag);
      $tagContents = strtolower(file_get_contents($file).'<br>'.$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).'<br>';
      checkTags($dir.'\\'.$file, $search);
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

谢谢

dim*_*414 5

您想要将输出刷新到客户端,请使用PHP的flush()函数.

也就是说,如果你在页面加载上进行复杂的处理,那就是糟糕的用户体验.它更复杂,但是如果你向用户提供一些东西,即使它只是一个空的但是完整的模板,你会提供更好的产品,然后像开心事件所暗示的那样,与AJAX异步地提取昂贵的数据.