PHP explode() Funzione
❮ Riferimento alla stringa PHP
Esempio
Rompi una stringa in un array:
<?php
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
?>
Definizione e utilizzo
La funzione esplode() suddivide una stringa in un array.
Nota: il parametro "separatore" non può essere una stringa vuota.
Nota: questa funzione è a sicurezza binaria.
Sintassi
explode(separator,string,limit)
Valori dei parametri
Parameter | Description |
---|---|
separator | Required. Specifies where to break the string |
string | Required. The string to split |
limit | Optional. Specifies the number of array elements to return. Possible values:
|
Dettagli tecnici
Valore di ritorno: | Restituisce una matrice di stringhe |
---|---|
Versione PHP: | 4+ |
Registro delle modifiche: | Il parametro limit è stato aggiunto in PHP 4.0.1 e il supporto per i limiti negativi è stato aggiunto in PHP 5.1.0 |
Altri esempi
Esempio
Utilizzo del parametro limit per restituire un numero di elementi dell'array:
<?php
$str = 'one,two,three,four';
// zero limit
print_r(explode(',',$str,0));
// positive limit
print_r(explode(',',$str,2));
// negative limit
print_r(explode(',',$str,-1));
?>
❮ Riferimento alla stringa PHP