The preg_last_error function is used to perform a regular expression match.
int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )
Searches subject for a match of the regular expression given by pattern.
Parameter description:
$pattern: The pattern to search for, in string form.
$subject: input string.
$matches: If the matches parameter is provided, it will be populated with search results. $matches[0] will contain the text matched by the full pattern, $matches[1] will contain the text matched by the first captured subgroup, and so on.
$flags: flags can be set to the following flag values:
PREG_OFFSET_CAPTURE: If this flag is passed, the string offset (relative to the target string) will be appended to the return for each occurrence of a match. Note: This will change the array filled in the matches parameter so that each element becomes a string where the 0th element is the matched string and the 1st element is the offset of the matched string in the target string subject. .
offset: Normally, the search starts from the beginning of the target string. The optional parameter offset is used to specify starting the search from an unknown point in the target string (unit is bytes).
Returns the number of matches for pattern. Its value will be 0 (no match) or 1 because preg_match() will stop searching after the first match. preg_match_all() differs from this in that it searches for the subject until it reaches the end. If an error occurs preg_match() returns FALSE.
The execution result is as follows:
Find the matching string php.
The execution result is as follows:
Matching string found. No matching string found.
The execution result is as follows:
domain name is: codercto.com
The execution result is as follows:
Array( [0] => foobar: 2008 [name] => foobar [1] => foobar [digit] => 2008 [2] => 2008)