RE: [PHP-DB] preg_math vs preg_match_all
| From: | Russell Johnson | Date: | Wed, 24 Nov 2004 08:33:39 +0000 |
| Subject: | RE: [PHP-DB] preg_math vs preg_match_all | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-37393@lists.php.net to get a copy of this message | ||
For those perl fans out there, preg_match_all adds the g (global) flag to the expression. So this:
preg_match('/foo/', $str, $match);
would be like
$str =~ /foo/;
preg_match_all('/foo/', $str, $match);
like
$str =~ /foo/g;
- Russ
p.s. - anyone coming from Perl to PHP can get a little hung up on the preg_* functions...
-----Mensaje original-----
De: Gerard Samuel [mailto:php-db@trini0.org]
Enviado el: Tuesday, November 23, 2004 2:37 PM
Para: Yemi Obembe
CC: php-db@lists.php.net
Asunto: Re: [PHP-DB] preg_math vs preg_match_all
Yemi Obembe wrote:
>Just want to know the difference between preg_match and preg_match_all.
>
preg_match stops after the first match.
preg_match_all gets *all* the matches.
E.g. If you have a string -> $str = "foofoo";
preg_match('/foo/', $str, $match); -> $match will have an array with one
"foo".
preg_match_all('/foo/', $str, $match); -> $match will have an array with
two "foo".
Thats basically it.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php