Last active
May 16, 2017 13:16
-
-
Save ildarkhasanshin/1c2c2e737edf9dae91a8879f763594a6 to your computer and use it in GitHub Desktop.
search in text by php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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