PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular

preg_match_all

Tags: PHP 5.x PHP 7.x PHP 8.x

preg_match_all — Perform a global regular expression match.

Description

preg_match_all(
    string $pattern,
string $subject,
array &$matches = null,
int $flags = 0,
int $offset = 0
): int|false|null
Searches subject for all matches to the regular expression given in pattern and puts them in matches in the order specified by flags. After the first match is found, the subsequent searches are continued on from end of the last match.

Parameters

pattern
The pattern to search for, as a string.
subject
The input string.
matches
Array of all matches in multi-dimensional array ordered according to flags.
flags
flags can be a combination of the following flags: PREG_PATTERN_ORDER, PREG_SET_ORDER, PREG_OFFSET_CAPTURE, PREG_UNMATCHED_AS_NULL
offset
Normally, the search starts from the beginning of the subject string. The optional parameter offset can be used to specify the alternate place from which to start the search (in bytes).

Return Values

preg_match() returns 1 if the pattern matches given subject, 0 if it does not, or false if an error occurred.