Hướng dẫn dùng nl2br trong PHP
Hàm Show Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức. Cú phápCú
pháp: Trong đó:
Ví dụCode echo "freetuts.net\n PHP functionn"; echo " Kết quả freetuts.net PHP functionn freetuts.net PHP functionn Code $string = "This\r\nis\n\ra\nstring\r"; echo nl2br($string); Tham khảo: php.net Bài viết này được đăng tại [free tuts .net] ❮ Tham chiếu chuỗi PHP Thí dụChèn ngắt dòng nơi xuất hiện dòng mới (\ n) trong chuỗi: echo nl2br("One line.\nAnother line."); Đầu ra trình duyệt của đoạn mã trên sẽ là: One line. Đầu ra HTML của đoạn mã trên sẽ là (Xem Nguồn): One line. Định nghĩa và Cách sử dụngHàm nl2br () chèn các ngắt dòng HTML ( Cú phápGiá trị tham số
Chi tiết kỹ thuật
Các ví dụ khácThí dụChèn ngắt dòng khi xuất hiện dòng mới (\ n), sử dụng tham số xhtml: echo nl2br("One line.\nAnother line.",false); Đầu ra trình duyệt của đoạn mã trên sẽ là: One line. Đầu ra HTML của đoạn mã trên sẽ là (Xem Nguồn): One
line. ❮ Tham chiếu chuỗi PHP (PHP 4, PHP 5, PHP 7, PHP 8) nl2br — Inserts HTML line breaks before all newlines in a string Descriptionnl2br(string Parametersstring The input string. use_xhtml Whether to use XHTML compatible line breaks or not. Return ValuesReturns the altered string. ExamplesExample #1 Using nl2br()
The above example will output: Example #2 Generating valid HTML markup using the
The above example will output: Welcome Example #3 Various newline separators
The above example will output: This See Also
CGameProgrammer at gmail dot com ¶ 17 years ago
ngkongs at gmail dot com ¶ 15 years ago
N/A ¶ 13 years ago
fquffio at live dot it ¶ 8 years ago
aabaev ¶ 3 years ago
Anders Norrbring ¶ 16 years ago
gautier dot michelin at gmail dot com ¶ 2 years ago
" ", explode("\n", $string))." ";?> By exploding on new lines & adding end & begin for p, it's easy to concat with .
" ", explode("\n", $string))." ";} ?>
Collette ¶ 2 years ago
buzanits at gmail dot com ¶ 4 years ago
nl("One\nTwo leo dot mauro dot desenv at gmail dot com ¶ 6 years ago
Justinas M. ¶ 6 years ago
nl2br_preg_R($string)
chad at nobodyfamous dot ca ¶ 5 years ago
blacknine313 at gmail dot com ¶ 14 years ago
darenschwenke at yahoo dot com ¶ 8 years ago
j dot mons54 at gmail dot com ¶ 10 years ago
hyponiq at gmail dot com ¶ 15 years ago
|