Funzione PHP wordwrap()
❮ Riferimento alla stringa PHP
Esempio
Avvolgi una stringa in nuove righe quando raggiunge una lunghezza specifica:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>\n");
?>
Definizione e utilizzo
La funzione wordwrap() avvolge una stringa in nuove righe quando raggiunge una lunghezza specifica.
Nota: questa funzione può lasciare spazi bianchi all'inizio di una riga.
Sintassi
wordwrap(string,width,break,cut)
Valori dei parametri
Parameter | Description |
---|---|
string | Required. Specifies the string to break up into lines |
width | Optional. Specifies the maximum line width. Default is 75 |
break | Optional. Specifies the characters to use as break. Default is "\n" |
cut |
Optional. Specifies whether words longer than the specified width should be wrapped:
|
Dettagli tecnici
Valore di ritorno: | Restituisce la stringa suddivisa in righe in caso di successo o FALSE in caso di errore. |
---|---|
Versione PHP: | 4.0.2+ |
Registro delle modifiche: | Il parametro cut è stato aggiunto in PHP 4.0.3 |
Altri esempi
Esempio
Utilizzando tutti i parametri:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>\n",TRUE);
?>
Esempio
Avvolgi una stringa in nuove righe:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15);
?>
L'output HTML del codice sopra sarà (Visualizza sorgente):
<!DOCTYPE html>
<html>
<body>
An example of a
long word is:
Supercalifragulistic
</body>
</html>
L'output del browser del codice sopra sarà:
An example of a long word is: Supercalifragulistic
❮ Riferimento alla stringa PHP