PHPize Online / SQLize Online

Articles    Popular

preg_match

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

preg_match — Perform a regular expression match

Description


preg_match(
    string $pattern,
    string $subject,
    array &$matches = null,
    int $flags = 0,
    int $offset = 0
): int|false
Searches subject for a match to the regular expression given in pattern.

Parameters

pattern
The pattern to search for, as a string.
subject
The input string.
matches
If matches is provided, then it is filled with the results of search. $matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on.
flags
flags can be a combination of the following flags: 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.

PHPize.online - New preg_match snippets