Jump to content

number of pattern matches


alarik149

Recommended Posts

[quote=PHP Manual]
PREG_PATTERN_ORDER

Orders results so that $matches[0] is an array of full pattern matches, $matches[1] is an array of strings matched by the first parenthesized subpattern, and so on.
[/quote]

With this in mind, you'd want to run your preg_match_all() function with the PREG_PATTERN_ORDER flag set. Then, you'd simply be able to count() all the results in $matches[0]:

[code]
<?php
preg_match_all($pattern, $String, $matches, PREG_PATTERN_ORDER);
echo "There were " . count($matches[0]) . " found!";
?>
[/code]

Hope this helps

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.