CKTIS / PHP
preg_match_all()
Raccoglie le corrispondenze senza sovrapposizioni e ne restituisce il numero, zero se assenti o false in caso di errore.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
preg_match_all(string $pattern, string $subject, array &$matches = null, int $flags = 0, int $offset = 0): int|falseRaccoglie le corrispondenze senza sovrapposizioni e ne restituisce il numero, zero se assenti o false in caso di errore. PREG_PATTERN_ORDER raggruppa per indice di cattura, PREG_SET_ORDER crea una riga per corrispondenza. PREG_UNMATCHED_AS_NULL indica i gruppi assenti con null.
Firma
preg_match_all(string $pattern, string $subject, array &$matches = null, int $flags = 0, int $offset = 0): int|false
Output dell’esempio
[2,[["A","A",null],["B2","B","2"]]]
Esempi
<?php
$n=preg_match_all("~([A-Z])(\\d)?~","A B2",$rows,PREG_SET_ORDER | PREG_UNMATCHED_AS_NULL);
echo json_encode([$n,$rows]);
Risultato
[2,[["A","A",null],["B2","B","2"]]]