$line_contents) { if (preg_match($pattern,$line_contents)>0) { if ( (self::flag($flags,'r') && !self::flag($flags,'h')) // recursive || (self::flag($flags,'H')) // or explicit ) { echo htmlentities($file).': '; } if (self::flag($flags,'n')) { echo $line_number.': '; } echo htmlentities($line_contents)."\n"; } } } public static function main($args, $env) { $me = array_shift($args); $flags = ''; while (substr($args[0],0,1) == '-') { $flags .= array_shift($args); } $flags = preg_replace('/[ -]/','',$flags); $pattern = array_shift($args); foreach ($args as $file) { if (self::flag($flags,'r')) { self::recurse_grep($pattern, $file, $flags); } else { self::grep($pattern, $file, $flags); } } } }