-
Notifications
You must be signed in to change notification settings - Fork 16
/
find.php
37 lines (37 loc) · 1.04 KB
/
find.php
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
#!/usr/bin/php
<?php
$str = 'Container';
$file = null;
$directory = getcwd();
$directory = './';
echo '<xmp>';
$rit = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST);
try {
$count = 0;
foreach ($rit as $file) {
//print 'processing ' . $file->getRealPath()."\n";
if ($file->isFile()) {
$path_parts = pathinfo($file->getRealPath());
if ('php' == $path_parts['extension']) {
$object = new SplFileObject($file->getRealPath());
while (!$object->eof()) {
$line = $object->getCurrentLine();
if (false !== ($pos = strpos($line, $str))) {
$count++;
print $file->getRealPath()."\n";
print $line;
print substr($line, $pos);
break;
}
}
}
} else {
//print 'processing ' . $file->getRealPath()."\n";
flush();
}
}
echo 'done ' . $count . ' files found with ' . $str;
} catch (Exception $e) {
die ('Exception caught: '. $e->getMessage());
}
?>