Forum und email

strspn

(PHP 4, PHP 5)

strspn — Trova la lunghezza di un testo che corrisponde alla maschera data

Descrizione

int strspn ( string $str1 , string $str2 [, int $start [, int $length ]] )

Restituisce la lunghezza di un segmento di str1 che contiene completamente i caratteri presenti in str2 .

Il seguente codice:

<?php
$var 
strspn("42 is the answer, what is the question ...""1234567890");
?>
assegnerà 2 a $var, poichè la stringa "42" è il più lungo segmento contenente i caratteri da "1234567890".

Dal PHP 4.3.0, strspn() accetta altri due parametri interi opzionali: start che può essere usato per indicare la posizione di inizio da cui cercare, e length per indicare la lunghezza della stringa da esaminare.

<?php
echo strspn("foo""o"12); // 2
?>

Nota: Questa funzione è binary-safe (gestisce correttamente i file binari)

Vedere anche strcspn().