Signatur
substr_count(string $haystack, string $needle, int $offset = 0, ?int $length = null): int
Beschreibung
substr_count('aaaa', 'aa') = 2, nicht 3.
Parameter
| Name | Typ | Default | Beschreibung |
|---|---|---|---|
| $haystack Pflicht | string | — | String. |
| $needle Pflicht | string | — | Teilstring. |
Rückgabewert
Typ
int
Beschreibung
Anzahl.
Beispiele
Zeilen zählen
<?php
echo substr_count($text, "\n") + 1;