Решение задачки (поиск)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
if ($dir = opendir('files/')):
while (false !== ($files = readdir($dir))):
if ($files != '.' && $files != '..'):
$filepath = 'files/'.$files;
$file = file($filepath);
$found = false;
foreach ($file as $line => $text):
$arr = array('vit');
foreach ($arr as $key):
if (strpos($text, $key) !== false):
$found = true;
$line_val[] = $line + 1;
$string[] = trim($text);
endif;
endforeach;
endforeach;
if($found == true):
$text = null;
$text .= 'File: '.$filepath;
$count = count($line_val);
for($i = 0; $i <= $count-1; $i++):
$text .= ' Line: '.$line_val[$i];
$text .= ' String: '.$string[$i];
endfor;
$line_val = null;
$good = 'good.txt';
file_put_contents($good, $text."\r\n", FILE_APPEND);
endif;
endif;
endwhile;
closedir($dir);
endif;