alarik149 Posted December 13, 2006 Share Posted December 13, 2006 OK,so,I have a pattern that scans a file and returnes all the matches into $matches[$x][$y] but I want to know how many matches Ive got.How do I do that?I use preg_match_all.regards... Link to comment https://forums.phpfreaks.com/topic/30485-number-of-pattern-matches/ Share on other sites More sharing options...
obsidian Posted December 13, 2006 Share Posted December 13, 2006 [quote=PHP Manual]PREG_PATTERN_ORDEROrders 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]<?phppreg_match_all($pattern, $String, $matches, PREG_PATTERN_ORDER);echo "There were " . count($matches[0]) . " found!";?>[/code]Hope this helps Link to comment https://forums.phpfreaks.com/topic/30485-number-of-pattern-matches/#findComment-140396 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.