CKTIS / PHP
preg_match_all()
Collect all non-overlapping matches and return their number, zero for none or false on error.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
preg_match_all(string $pattern, string $subject, array &$matches = null, int $flags = 0, int $offset = 0): int|falseCollect all non-overlapping matches and return their number, zero for none or false on error. The default PREG_PATTERN_ORDER groups results by capture index. PREG_SET_ORDER instead builds one row per match. PREG_UNMATCHED_AS_NULL preserves absent optional groups as null.
Signature
preg_match_all(string $pattern, string $subject, array &$matches = null, int $flags = 0, int $offset = 0): int|false
Example output
[2,[["A","A",null],["B2","B","2"]]]
Examples
<?php
$n=preg_match_all("~([A-Z])(\\d)?~","A B2",$rows,PREG_SET_ORDER | PREG_UNMATCHED_AS_NULL);
echo json_encode([$n,$rows]);
Result
[2,[["A","A",null],["B2","B","2"]]]