Parm Dhillon
Parm Dhillon

Reputation: 65

I want to search files and folder in directories and sub directories php

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

Answers (2)

arkascha
arkascha

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

Med
Med

Reputation: 2063

use

 '/YOURSEARCHSTRING/i'

The i pattern modifier will match both upper and lower case word

Upvotes: 1

Related Questions