(PHP 4, PHP 5, PHP 7, PHP 8)
preg_match(
string $pattern,
string $subject,
array &$matches = null,
int $flags = 0,
int $offset = 0
)
搜索subject与pattern定的正则表达式的一个匹配
<?php
$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, substr($subject,3), $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
?>
以上示例会输出:
Array
(
[0] => Array
(
[0] => def
[1] => 0
)
)