I’ve made a class that will search files for a given word/words. All you have to do is set parent folder, query and you’ll get results.
Script uses objects and I plan to make it better and more features. For now it’s very simple.
Example of how to use my class.
$search = new searchFiles();
//We need to set some params
/Regular expression to determine which files will be searched (only those that match pattern)
$search -> setFilter ( '/.*\.php/i' );
//Search as whole word or split it into smaller chunks and search them individually
$search -> setIsWholeWord ( false );
//Start tag that will wrap result
$search -> setBegin ( '<span style="color: red">' );
//End tag that will wrap result
$search -> setEnd ( '</span>' );
//Is our query regular expression
$search -> setUseRegex ( false );
//Do we want to search subfolders?
$search -> setIsRecursive ( true );
//Or you can do it like this
/*
$search -> setFilter ( '/.*\.php/i' ) -> setIsWholeWord ( false ) -> setBegin ( '<span style="color: red">' )
-> setEnd ( '</span>' ) -> setUseRegex ( false ) -> setIsRecursive ( true );
*/
//Here we set our query and start folder (if we sat TRUE to recursive all sub folders will be searched)
$rez = $search -> search ( 'php', 'C:\folder' );
//Loop through each file that has match
foreach ( $rez as $k ) {
//Echo file path
echo '<strong>', $k -> getFileName(), '</strong>';
//Loop through each row that has result
foreach ($k as $v) {
//Echo line number and line that has match (result is wrapped in start/end tag)
echo $v -> getLine(), ':', $v -> getText(), '';
}
}
Later I’ll add more features and make it better. Please report any bug.
You can download it here.
ur good..