note 23911 deleted from function.preg-grep by sniper
| From: | sniper@php.net | Date: | Tue, 30 Sep 2003 12:22:00 +0000 |
| Subject: | note 23911 deleted from function.preg-grep by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57427@lists.php.net to get a copy of this message | ||
Note Submitter: pshirkey_at_boosthardware.com
----
It took me a while to get this.
I needed to parse a file and return a line based on a variable from a form. Unfortunately I have
only access to a php3 server. This does it for me.
*Nb the delimiters around $pattern eg. /$pattern/
Otherwise I got an error about:
Warning: Delimiter must not be alphanumeric or backslash
----
$fcontents = file ('file.php3', "r");
function preg_grep($pattern, $array) {
while( list($key, $val) = each($array)) {
if (preg_match("/$pattern/", $val)){
echo $val;
}
}
}
preg_grep($var, $fcontents);
----