Skip to content

Instantly share code, notes, and snippets.

@divinity76
Last active May 7, 2020 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divinity76/ec70ed3b1ed778780f58468c2b2f7632 to your computer and use it in GitHub Desktop.
Save divinity76/ec70ed3b1ed778780f58468c2b2f7632 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types = 1);
$search_needles = array();
$search_regex = array();
$start_dir = implode(DIRECTORY_SEPARATOR, [
__DIR__,
"..",
'easyad'
]);
$start_dir = realpath($start_dir);
if (false === $start_dir) {
die("error: startdir isn't readable.\n");
}
if (! is_dir($start_dir)) {
die("error: startdir isn't a directory.\n");
}
$start_dir = rtrim($start_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
function search(string $dir, array $search_needles, array $search_regex): void
{
$dir = rtrim($dir, DIRECTORY_SEPARATOR);
$files = glob($dir . DIRECTORY_SEPARATOR . "*", GLOB_NOESCAPE | GLOB_NOSORT);
foreach ($files as $file) {
if (is_dir($file)) {
echo ",";
search($file, $search_needles, $search_regex);
} else {
echo ".";
$c = file_get_contents($file);
if (empty($c) && $c !== "0") {
continue;
}
foreach ($search_needles as $needle) {
if (false !== stripos($c, $needle)) {
echo "\nMATCH: {$needle}: {$file}\n";
}
}
foreach ($search_regex as $rex) {
if (preg_match($rex, $c)) {
echo "\nMATCH: {$rex}: {$file}\n";
}
}
}
}
}
search($start_dir, $search_needles, $search_regex);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment