diff options
author | Andreas Gohr <andi@splitbrain.org> | 2006-05-11 21:14:50 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2006-05-11 21:14:50 +0200 |
commit | 7421c3cce15c5712b2bfb76cd5dd857771e8b6b8 (patch) | |
tree | 94f8835d3a9a260c10900de23b622beda75d72d4 /inc/io.php | |
parent | 4fa2dffce72d182e25295de4947077cf52ba1f2b (diff) | |
download | rpg-7421c3cce15c5712b2bfb76cd5dd857771e8b6b8.tar.gz rpg-7421c3cce15c5712b2bfb76cd5dd857771e8b6b8.tar.bz2 |
more info is gathered on metaupdate in background indexer
The background indexer now gathers info on contributors and modification
dates from the changelog when adding the missing meta info.
A new io_grep function was added which might be useful for other parts in
the Wiki as well.
darcs-hash:20060511191450-7ad00-baba1b48ea03b823c88a480862c612316f159b5a.gz
Diffstat (limited to 'inc/io.php')
-rw-r--r-- | inc/io.php | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/inc/io.php b/inc/io.php index ae1a3611c..a44e498a2 100644 --- a/inc/io.php +++ b/inc/io.php @@ -366,4 +366,45 @@ function io_runcmd($cmd){ return $ret; } +/** + * Search a file for matching lines + * + * This is probably not faster than file()+preg_grep() but less + * memory intensive because not the whole file needs to be loaded + * at once. + * + * @author Andreas Gohr <andi@splitbrain.org> + * @param string $file The file to search + * @param string $pattern PCRE pattern + * @param int $max How many lines to return (0 for all) + * @param bool $baxkref When true returns array with backreferences instead of lines + * @return matching lines or backref, false on error + */ +function io_grep($file,$pattern,$max=0,$backref=false){ + $fh = @fopen($file,'r'); + if(!$fh) return false; + $matches = array(); + + $cnt = 0; + $line = ''; + while (!feof($fh)) { + $line .= fgets($fh, 4096); // read full line + if(substr($line,-1) != "\n") continue; + + // check if line matches + if(preg_match($pattern,$line,$match)){ + if($backref){ + $matches[] = $match; + }else{ + $matches[] = $line; + } + $cnt++; + } + if($max && $max == $cnt) break; + $line = ''; + } + fclose($fh); + return $matches; +} + //Setup VIM: ex: et ts=2 enc=utf-8 : |