File_Find::_determineRegex PHP Méthode

_determineRegex() public méthode

internal function to determine the type of regular expression to use, implemented by File_Find::glob() and File_Find::search()
public _determineRegex ( $pattern, string $type ) : string
$type string given RegExp type
Résultat string kind of function ( "eregi", "ereg" or "preg_match") ;
    function _determineRegex($pattern, $type)
    {
        if (!strcasecmp($type, 'shell')) {
            $match_function = 'File_Find_match_shell';
        } else {
            if (!strcasecmp($type, 'perl')) {
                $match_function = 'preg_match';
            } else {
                if (!strcasecmp(substr($pattern, -2), '/i')) {
                    $match_function = 'eregi';
                } else {
                    $match_function = 'ereg';
                }
            }
        }
        return $match_function;
    }

Usage Example

Exemple #1
0
 /**
  * Search the specified directory tree with the specified pattern.  Return
  * an array containing all matching files (no directories included).
  *
  * @param string $pattern the pattern to match every file with.
  *
  * @param string $directory the directory tree to search in.
  *
  * @param string $type the type of regular expression support to use, either
  * 'php' or 'perl'.
  *
  * @param bool $fullpath whether the regex should be matched against the
  * full path or only against the filename
  *
  * @param string $match can be either 'files', 'dirs' or 'both' to specify
  * the kind of list to return
  *
  * @return array a list of files matching the pattern parameter in the the
  * directory path specified by the directory parameter
  *
  * @author Sterling Hughes <*****@*****.**>
  * @access public
  * @static
  */
 function &search($pattern, $directory, $type = 'php', $fullpath = true, $match = 'files')
 {
     $matches = array();
     list($directories, $files) = File_Find::maptree($directory);
     switch ($match) {
         case 'directories':
             $data = $directories;
             break;
         case 'both':
             $data = array_merge($directories, $files);
             break;
         case 'files':
         default:
             $data = $files;
     }
     unset($files, $directories);
     $match_function = File_Find::_determineRegex($pattern, $type);
     reset($data);
     while (list(, $entry) = each($data)) {
         if ($match_function($pattern, $fullpath ? $entry : basename($entry))) {
             $matches[] = $entry;
         }
     }
     return $matches;
 }
All Usage Examples Of File_Find::_determineRegex