strtok()
(funzione PHP) divide una stringa in stringhe più piccole, che restituisce un pezzo alla volta (token) fino al termine, allorché restituisce false
.
tips&tricks
Consente di attraversare una stringa.
Sintassi
strtok($stringa, $separatore);
parametro | descrizione |
---|---|
$stringa | La stringa da processare. Il parametro è necessario solo la prima volta (ed ogni volta che è presente, la funzione reinizializza l’iteratore) |
$separatore | Il separatore delle substringhe |
Esempi
$stringa = "A,B,C,D"; echo $primo = strtok($stringa, ","); // A echo $secondo = strtok(","); // B $token = strtok($stringa, ","); while ($token !== false) { echo("{$token}\n"); $token = strtok(","); // 1 solo argomento, dalla seconda volta in poi... } /* RISULTATO A B C D */
0 Comment