The preg_match_all function is used to perform a global regular expression match.
int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG_PATTERN_ORDER [, int $offset = 0 ]]] )
Search the subject for all matching results matching pattern with the given regular expression and output them to matches in the order specified by flag.
After the first match is found, the subsequence search continues from the last matching position.
Parameter description:
$pattern: The pattern to search for, in string form.
$subject: input string.
$matches: multi-dimensional array, output all matching results as output parameters, array sorting is specified by flags.
$flags: can be used in combination with the following tags (note that PREG_PATTERN_ORDER and PREG_SET_ORDER cannot be used at the same time):
PREG_PATTERN_ORDER: The results are sorted as $matches[0] holds all matches of the complete pattern, $matches[1] holds all matches of the first subgroup, and so on.
PREG_SET_ORDER: The results are sorted as $matches[0] contains all matches (including subgroups) obtained by the first match, $matches[1] is an array containing all matches (including subgroups) obtained by the second match, so that analogy.
PREG_OFFSET_CAPTURE: If this flag is passed, each found match is returned with its offset relative to the target string increased.
offset: Usually, the search starts from the beginning of the target string. The optional parameter offset is used to start searching from the specified position in the target string (unit is bytes).
Returns the complete number of matches (possibly 0), or FALSE if an error occurs.
The execution result is as follows:
Array( [0] => <b>PHP</b> [1] => <b>Programming Language</b>)
The execution result is as follows:
matched: <b>bold text</b>part 1: <b>part 2: bpart 3: bold textpart 4: </b>matched: <a href=howdy.html>click me</a>part 1: <a href=howdy.html>part 2: apart 3: click mepart 4: </a>