Reputation: 65
I want to search files and folders in directory or its all sub-directories.
I'm using this code:
<?php
$a = new RegexIterator(
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator('files')
),
'/Desi Indian/',
RegexIterator::MATCH
);
foreach ($a as $v) {
echo "$v\n"; //$v will be the filename
}
?>
But, the problem is, like a file name is 'Wayne' and if search string is 'wayne', then it doesn't show any search result. Ideas?
Upvotes: 0
Views: 53
Reputation: 42925
But, the problem is , Like a file name is 'Wayne' and if search string is 'wayne', then it will not show any search results.
This sounds like a question of searching case insensitive. Regular expressions can be given additional processing flags, amongst them i
for the purpose at hand. So just replace your pattern to '/Desi Indian/i'
and you should match the file names regardless of their cases.
You may want to read a bit about those flags, or modifiers how they are called: http://php.net/manual/en/reference.pcre.pattern.modifiers.php
Upvotes: 1
Reputation: 2063
use
'/YOURSEARCHSTRING/i'
The i
pattern modifier will match both upper and lower case word
Upvotes: 1