我正在放在一起搜索引擎在PHP中循環了一些目錄和回聲濾波結果,因爲它去了。回聲頁面,而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);
}
}
}
感謝
那麼你還沒有顯示你的代碼,這樣就可以給出關於如何修改代碼以在搜索過程中回顯結果的建議。 – 2013-03-22 20:01:31
@MikeBrant代碼添加。 – John 2013-03-22 20:11:42