';
foreach($array as $file => $lines)
{
echo '
', $file, ': ';
foreach($lines as $line)
echo $line, ', ';
echo '';
}
echo '
';
// Scan a directory recursively, thanks to "groundup over at simplemachines.org" for original code.
function scandir__recursive($dir, $search)
{
global $array;
if(!isset($array))
$array = array();
$return = array();
$opendir = scandir($dir);
foreach ($opendir as $file)
{
// Most files that begin with . are not useful to us, SMF doesn't do this.
if (substr ($file, 0, 1) == '.')
continue;
$full_path = $dir . '/' . $file;
// This is another directory.
if (is_dir(str_replace('\\', '/', $full_path)))
scandir__recursive($full_path, $search);
else
{
// Sadly, we need to count line by line to get correct line numbers.
$contents = explode("\n", file_get_contents($full_path));
foreach($contents as $line => $opened_line)
{
preg_match_all($search, $opened_line, $matches);
if (!empty($matches[0]))
foreach ($matches[0] as $key => $match)
// We cheat here and add + 1 since our array started with 0
$array[$file][] = $line + 1;
}
}
}
}
?>