The preg_match_all() function matches all occurrences of pattern in string.
It will place these matches in the array pattern_array in the order you specify using the optional input parameter order. There are two possible types of order −
PREG_PATTERN_ORDER − is the default if the optional order parameter is not included. PREG_PATTERN_ORDER specifies the order in the way that you might think most logical; $pattern_array[0] is an array of all complete pattern matches, $pattern_array[1] is an array of all strings matching the first parenthesized regexp, and so on.
PREG_SET_ORDER − will order the array a bit differently than the default setting. $pattern_array[0] will contain elements matched by the first parenthesized regexp, $pattern_array[1] will contain elements matched by the second parenthesized regexp, and so on.
The function returns the number of matching.
<?php $text = <<<EOT The big bang bonged under the bung. EOT; echo preg_match_all('@b.n?g@', $text, $matches); print_r($matches); ?>