Base di conoscenzaCentro esami
ITItaliano
Scegli la lingua13

CKTIS / PHP

substr_count()

Conta le occorrenze non sovrapposte distinguendo le maiuscole in una finestra di byte.

Versione: PHP 8.4; repository runtime, production runtime not attested

Sintassi

substr_count(string $haystack, string $needle, int $offset = 0, ?int $length = null): int

Conta le occorrenze non sovrapposte distinguendo le maiuscole in una finestra di byte. Offset e lunghezza facoltativa delimitano l’area, una lunghezza negativa esclude byte finali. Un modello vuoto genera ValueError.

Firma

substr_count(string $haystack, string $needle, int $offset = 0, ?int $length = null): int

Output dell’esempio

[2,1,1]

Esempi

<?php
echo json_encode([substr_count("aaaa","aa"),substr_count("ababa","aba"),substr_count("xxabABab","ab",2,-2)]);

Risultato

[2,1,1]

Fonti