PHP wordwrap() Fungsi
Contoh
Bungkus string menjadi baris baru ketika mencapai panjang tertentu:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>\n");
?>
Definisi dan Penggunaan
Fungsi wordwrap() membungkus string menjadi baris baru ketika mencapai panjang tertentu.
Catatan: Fungsi ini mungkin meninggalkan spasi putih di awal baris.
Sintaksis
wordwrap(string,width,break,cut)
Nilai Parameter
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:
|
Detail Teknis
Nilai Kembali: | Mengembalikan string yang dipecah menjadi beberapa baris saat berhasil, atau FALSE saat gagal. |
---|---|
Versi PHP: | 4.0.2+ |
Catatan perubahan: | Parameter cut ditambahkan di PHP 4.0.3 |
Lebih Banyak Contoh
Contoh
Menggunakan semua parameter:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>\n",TRUE);
?>
Contoh
Bungkus string menjadi baris baru:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15);
?>
Output HTML dari kode di atas adalah (Lihat Sumber):
<!DOCTYPE html>
<html>
<body>
An example of a
long word is:
Supercalifragulistic
</body>
</html>
Output browser dari kode di atas adalah:
An example of a long word is: Supercalifragulistic
Referensi String PHP