我有,不斷地重複輸出約40或50倍PHP print語句的問題,然後停止。我以爲它應該只打印一行。我對PHP還是比較陌生,所以我不明白我做錯了什麼。相關代碼位於代碼片段的底部。PHP重複打印語句
在此先感謝.....
<?php
$query = $_POST['query'];
find_files('.');
function find_files($seed) {
if(! is_dir($seed)) return false;
$files = array();
$dirs = array($seed);
while(NULL !== ($dir = array_pop($dirs))) {
if($dh = opendir($dir)) {
while(false !== ($file = readdir($dh))) {
if($file == '.' || $file == '..') continue;
$path = $dir . '/' . $file;
if(is_dir($path)) {
$dirs[] = $path;
} else {
if(preg_match('/^.*\.(php[\d]?|js|txt)$/i', $path)) {
check_files($path);
}
}
}
closedir($dh);
}
}
}
function check_files($this_file) {
$query = $_POST['query'];
$str_to_find = $query;
if ((isset($str_to_find)) && (empty($str_to_find))) {
print '<p>Your search produced no results</p>';
} else {
if(!($content = file_get_contents($this_file))) {
echo("<p>Could not check $this_file</p>\n");
} else {
if(stristr($content, $str_to_find)) {
echo("<p>$this_file -> contains $str_to_find</p>\n");
}
}
unset($content);
}
}
?>
它是「你的搜尋無」那是重複? – spencercw 2012-02-24 23:33:25
是的,這是正確的 – 2012-02-24 23:33:42
也許您呼叫Checkfiles反覆(在由spencercw暗示)? - > check_files($路徑);它處於while()循環中,所以每次循環時都會打印。 – user978122 2012-02-24 23:36:29