Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / PHP

preg_match_all()

Reúne coincidencias sin solapamiento y devuelve su número, cero si no hay o false en caso de error.

Versión: PHP 8.4; repository runtime, production runtime not attested

Sintaxis

preg_match_all(string $pattern, string $subject, array &$matches = null, int $flags = 0, int $offset = 0): int|false

Reúne coincidencias sin solapamiento y devuelve su número, cero si no hay o false en caso de error. PREG_PATTERN_ORDER agrupa por índice de captura y PREG_SET_ORDER genera una fila por coincidencia. PREG_UNMATCHED_AS_NULL representa los grupos ausentes con null.

Firma

preg_match_all(string $pattern, string $subject, array &$matches = null, int $flags = 0, int $offset = 0): int|false

Salida del ejemplo

[2,[["A","A",null],["B2","B","2"]]]

Ejemplos

<?php
$n=preg_match_all("~([A-Z])(\\d)?~","A B2",$rows,PREG_SET_ORDER | PREG_UNMATCHED_AS_NULL);
echo json_encode([$n,$rows]);

Resultado

[2,[["A","A",null],["B2","B","2"]]]

Fuentes