note 23911 added to function.preg-grep

From: Date: Wed, 31 Jul 2002 19:03:49 +0000
Subject: note 23911 added to function.preg-grep
Groups: php.notes 
Request: Send a blank email to php-notes+get-34054@lists.php.net to get a copy of this message
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); ---- -- http://www.php.net/manual/en/function.preg-grep.php http://master.php.net/manage/user-notes.php?action=edit+23911 http://master.php.net/manage/user-notes.php?action=delete+23911 http://master.php.net/manage/user-notes.php?action=reject+23911

« previous php.notes (#34054) next »