PHP nl2br() Fungsi
Contoh
Sisipkan jeda baris di mana baris baru (\n) muncul dalam string:
<?php
echo nl2br("One line.\nAnother line.");
?>
Output browser dari kode di atas adalah:
One line.
Another line.
Output HTML dari kode di atas adalah (Lihat Sumber):
One line.<br />
Another line.
Definisi dan Penggunaan
Fungsi nl2br() menyisipkan jeda baris HTML (<br> atau <br />) di depan setiap baris baru (\n) dalam sebuah string.
Sintaksis
nl2br(string,xhtml)
Nilai Parameter
Parameter | Description |
---|---|
string | Required. Specifies the string to check |
xhtml | Optional. A boolean value that indicates whether or not to use XHTML compatible line breaks:
|
Detail Teknis
Nilai Kembali: | Mengembalikan string yang dikonversi |
---|---|
Versi PHP: | 4+ |
Catatan perubahan: | Parameter xhtml telah ditambahkan di PHP 5.3. Sebelum PHP 4.0.5, disisipkan <br>. Setelah PHP 4.0.5 itu menyisipkan <br />. |
Lebih Banyak Contoh
Contoh
Sisipkan jeda baris di mana baris baru (\n) muncul, menggunakan parameter xhtml:
<?php
echo nl2br("One line.\nAnother line.",false);
?>
Output browser dari kode di atas adalah:
One line.
Another line.
Output HTML dari kode di atas adalah (Lihat Sumber):
One line.<br>
Another line.
Referensi String PHP