Re: preg_match() vs. preg_match_all()
| From: | Michael Dearman | Date: | Fri, 09 Feb 2001 10:05:41 +0000 |
| Subject: | Re: preg_match() vs. preg_match_all() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-38919@lists.php.net to get a copy of this message | ||
CC Zona wrote:
>
> What is the functional difference between preg_match() and
> preg_match_all()? I've puzzled over the manual descriptions for both,
> checked the list archives and faqts.com, and still can't figure out why
> they seem to return different results for the same pattern searches.
>
Use a some text to match against where there's many places for a match
to occur. When you use the PREG_PATTERN_ORDER, for the order argument with
preg_match_all, it's like a global match, collecting the matches and
subpatterns (obtained by using parenthesis, which will 'remember' the
subpatterns) in the 2dim array for your viewing pleasure.
Something like that. I usually have to wrestle with it a bit to get it straight
how the results from the subpattern matches (from the memorizing parens) are
ordered in the array to get the a loop to spit everything back out correctly.
If your nesting parens, I think it's you just start counting the opening paren
from the left, and they'll match sequentially as indexes in the associated array
for that particular match. Well, the 0 index is the entire match, and the subpat
matches pick up at index 1.
But, if the winds blowing from the east, and .....
;-)
MD
> TIA
>
> --
> CC
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net