简化定义
preg_match (string $pattern , string $subject [array &$matches] ) : int
说明:
$pattern 搜索模式
$subject 字符串
$matches 搜索结果(可选)
界定符:/
示例
// 只校验结果
echo preg_match('/\d+/', '1234');
// 1
// 获取匹配结果
if(preg_match('/age=(\d+)/', 'age=16', $matches)){
var_dump($matches);
}
/**
array(2) {
[0]=> string(6) "age=16"
[1]=> string(2) "16"
}
*/
参考
PHP 正则表达式
https://www.php.net/manual/zh/function.preg-match.php