我有一个代码,用于搜索所有文件中的指定字符串并检查子目录。最后我返回一个数组,其中包含文件名和行号。无论如何我只得到一个填充了最后一个被检查文件夹的数组。
function scan2($dir,$pre,$counter,$arr) {
include("config.php"); //CONTAINS AN ARRAY OF PATHS WHICH CAN BE SKIPPED
$mergedArray['gesamt'] = 0;
if($counter > 0)
{
$mergedArray['gesamt'] = $counter; //COUNTS THE TOTAL AMOUNT OF ENTRYS
}
$pre.= "-";
$dh = opendir($dir);
while($file = readdir($dh))
{
if($file != "." && $file != "..")
{
if(is_dir($dir."/".$file) && !in_array("$dir/$file",$pfade)) //IF IS DIRECTORY
{
scan2($dir.'/'.$file,$pre,$counter,$arr);
}
else // IF IS FILE
{
$handle = fopen($dir.'/'.$file, "r");
$string = "";
$raw = "";
$count = 0;
$counter = $counter;
$info = pathinfo($dir."/".$file);
if($info["extension"] == "php" || $info["extension"] == "js" || $info["extension"] == "html" || $info["extension"] == "xml")
{
while (($line = fgets($handle)) !== false)
{
$count++;
if(strpos($line,$_GET['suche']) == true)
{
$string .= $count.',';
$counter++;
}
$raw = substr($string, 0, -1);
}
$pfad = $dir.'/'.$file;
echo $pfad.' -- '.$raw.'<hr>';
if(strlen($raw) > 0) {
$mergedArray['eintraege'][$pfad] = $raw;
}
fclose($handle);
}
}
}
}
array_push($arr, $mergedArray);
closedir($dh);
return $mergedArray;
}
// OUTSIDE THE FUNCTION
$arr = Array();
$tt = scan2("C:/xampp1/htdocs_micha","", 0, $arr);
echo'<pre>';
print_r($tt);
echo'</pre>';
我真的希望你们理解我的问题并且可以帮助我。
最好的问候:我