<?php
// FOLDER TO SEARCH IN
$target_folder = "./";
// TEXT TO SEARCH FOR
$searchtext = 'in_array';
// CALL SEARCH FUNCTION
$res = doSearch($target_folder, $searchtext);
// DUMP RESULTS
echo "<pre>" . print_r($res, true) . "</pre>";
// RECURSIVE SEARCH FUNCTION
function doSearch($target, $searchtext) {
$results = array();
if (is_dir($target)) {
if ($dh = opendir($target)) {
while(($file = readdir($dh)) != false) {
if ($file == '.' || $file == '..') continue;
if (is_dir($file)) {
$subdir = "{$target}{$file}/";
$results = array_merge($results, doSearch($subdir, $searchtext));
}
else {
$ext = strtolower(end(explode('.', $file)));
if ( $ext == 'php') {
$path = $target . $file;
if( strpos(file_get_contents($path),$searchtext) !== false) {
$results[] = $path;
}
}
}
}
closedir($dh);
}
}
return $results;
}
There are many tools for searching through files for specific strings or patterns - they differ based on the use-case.