PHP -Tutorial

PHP-HOME PHP-Einführung PHP-Installation PHP-Syntax PHP-Kommentare PHP-Variablen PHP-Echo / Drucken PHP-Datentypen PHP-Strings PHP-Nummern PHP-Mathematik PHP-Konstanten PHP-Operatoren PHP If...Else...Elseif PHP-Schalter PHP-Schleifen PHP-Funktionen PHP-Arrays PHP-Superglobals PHP-RegEx

PHP -Formulare

Handhabung von PHP-Formularen PHP-Formularvalidierung PHP-Formular erforderlich PHP-Formular-URL/E-Mail PHP-Formular vollständig

PHP- Erweitert

PHP-Datum und -Zeit PHP einschließen Umgang mit PHP-Dateien PHP-Datei öffnen/lesen PHP-Datei erstellen/schreiben Hochladen von PHP-Dateien PHP-Cookies PHP-Sitzungen PHP-Filter PHP-Filter für Fortgeschrittene PHP-Callback-Funktionen PHP-JSON PHP-Ausnahmen

PHP -OOP

PHP Was ist OOP PHP-Klassen/Objekte PHP-Konstruktor PHP-Destruktor PHP-Zugriffsmodifikatoren PHP-Vererbung PHP-Konstanten Abstrakte PHP-Klassen PHP-Schnittstellen PHP-Eigenschaften Statische PHP-Methoden Statische PHP-Eigenschaften PHP-Namespaces PHP-Iterables

MySQL- Datenbank

MySQL-Datenbank MySQL Connect MySQL-DB erstellen MySQL-Tabelle erstellen MySQL-Daten einfügen MySQL Letzte ID abrufen MySQL Mehrfach einfügen MySQL vorbereitet MySQL Select-Daten MySQL-Wo MySQL-Reihenfolge nach MySQL-Daten löschen MySQL-Update-Daten MySQL-Limit-Daten

PHP- XML

PHP-XML-Parser PHP-SimpleXML-Parser PHP SimpleXML - Get PHP-XML-Expat PHP-XML-DOM

PHP -AJAX

AJAX-Einführung AJAX-PHP AJAX-Datenbank AJAX-XML AJAX Live-Suche AJAX-Umfrage

PHP- Beispiele

PHP-Beispiele PHP-Compiler PHP-Quiz PHP-Übungen PHP-Zertifikat

PHP- Referenz

PHP-Übersicht PHP-Array PHP-Kalender PHP-Datum PHP-Verzeichnis PHP-Fehler PHP-Ausnahme PHP-Dateisystem PHP-Filter PHP-FTP PHP-JSON PHP-Schlüsselwörter PHP-Libxml PHP-Mail PHP-Mathematik PHP-Sonstiges PHP MySQLi PHP-Netzwerk PHP-Ausgabesteuerung PHP-RegEx PHP-SimpleXML PHP-Stream PHP-String Umgang mit PHP-Variablen PHP-XML-Parser PHP-Zip PHP-Zeitzonen

PHP preg_match_all() Funktion

❮ PHP-RegExp-Referenz

Beispiel

Finden Sie alle Vorkommen von "ain" in einer Zeichenfolge:

<?php
$str = "The rain in SPAIN falls mainly on the plains.";
$pattern = "/ain/i";
if(preg_match_all($pattern, $str, $matches)) {
  print_r($matches);
}
?>

Definition und Verwendung

Die preg_match_all()Funktion gibt die Anzahl der Übereinstimmungen eines Musters zurück, die in einer Zeichenfolge gefunden wurden, und füllt eine Variable mit den gefundenen Übereinstimmungen.


Syntax

preg_match_all(pattern, input, matches, flags, offset)

Parameterwerte

Parameter Description
pattern Required. Contains a regular expression indicating what to search for
input Required. The string in which the search will be performed
matches Optional. The variable used in this parameter will be populated with an array containing all of the matches that were found
flags Optional. A set of options that change how the matches array is structured.

One of the following structures may be selected:
  • PREG_PATTERN_ORDER - Default. Each element in the matches array is an array of matches from the same grouping in the regular expression, with index 0 corresponding to matches of the whole expression and the remaining indices for subpattern matches.
  • PREG_SET_ORDER - Each element in the matches array contains matches of all groupings for one of the found matches in the string.
Any number of the following options may be applied:
  • PREG_OFFSET_CAPTURE - When this option is enabled, each match, instead of being a string, will be an array where the first element is a substring containing the match and the second element is the position of the first character of the substring in the input.
  • PREG_UNMATCHED_AS_NULL - When this option is enabled, unmatched subpatterns will be returned as NULL instead of as an empty string.
offset Optional. Defaults to 0. Indicates how far into the string to begin searching. The preg_match() function will not find matches that occur before the position given in this parameter

Technische Details

Rückgabewert: Gibt die Anzahl der gefundenen Übereinstimmungen oder falsch zurück, wenn ein Fehler aufgetreten ist
PHP-Version: 4+
Änderungsprotokoll: PHP 7.2 – Flag PREG_UNMATCHED_AS_NULL hinzugefügt.

PHP 5.4 – Der Parameter „Matches“ wurde optional . PHP 5.3.6

– Die Funktion gibt „false“ zurück, wenn der Offset länger als die Länge der Eingabe ist.

) und (? <name>) Syntax zusätzlich zur vorherigen (?P<name>) Syntax

Mehr Beispiele

Beispiel

Verwenden Sie PREG_PATTERN_ORDER, um die Struktur des Match -Arrays festzulegen. In diesem Beispiel enthält jedes Element im matchs -Array alle Übereinstimmungen für eine der Gruppierungen des regulären Ausdrucks.

<?php
$str = "abc ABC";
$pattern = "/((a)b)(c)/i";
if(preg_match_all($pattern, $str, $matches, PREG_PATTERN_ORDER)) {
  print_r($matches);
}
?>

❮ PHP-RegExp-Referenz