Skip to content

Instantly share code, notes, and snippets.

@ildarkhasanshin
Last active May 16, 2017 13:16
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 ildarkhasanshin/1c2c2e737edf9dae91a8879f763594a6 to your computer and use it in GitHub Desktop.
Save ildarkhasanshin/1c2c2e737edf9dae91a8879f763594a6 to your computer and use it in GitHub Desktop.
search in text by php
<?php
function files_list($dir, &$files, $types_ar, $required_text) {
$fp = opendir($dir);
while ($file = readdir($fp)) {
$path = $dir . '/' . $file;
if (is_file($path)) {
if (in_array(end(explode('.', $file)), $types_ar)) {
$files[] = $path;
$contents = file_get_contents($path);
$pos = strpos($contents, $required_text);
if ($pos !== false) {
echo $path . '<br />';
}
}
} elseif ($file !== '.' && $file !== '..' && is_dir($path)) {
files_list($path, $files, $types_ar, $required_text);
}
}
closedir($fp);
}
$files = array();
files_list($_SERVER['DOCUMENT_ROOT'], $files, array('php'), 'my_text');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment