PHP Nl2br() Function - W3Schools
PHP nl2br() Function
❮ PHP String Reference
Example
Insert line breaks where newlines (\n) occur in the string:
<?php echo nl2br("One line.\nAnother line."); ?>The browser output of the code above will be:
One line. Another line.The HTML output of the code above will be (View Source):
One line.<br /> Another line. Try it Yourself »Definition and Usage
The nl2br() function inserts HTML line breaks (<br> or <br />) in front of each newline (\n) in a string.
Syntax
nl2br(string,xhtml)Parameter Values
| 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:
|
Technical Details
| Return Value: | Returns the converted string |
|---|---|
| PHP Version: | 4+ |
More Examples
Example
Insert line breaks where newlines (\n) occur, using the xhtml parameter:
<?php echo nl2br("One line.\nAnother line.",false); ?>The browser output of the code above will be:
One line. Another line.The HTML output of the code above will be (View Source):
One line.<br> Another line. Try it Yourself » ❮ PHP String Reference ★ +1 Sign in to track progressTừ khóa » N Php
-
PHP - How To Create A Newline Character? - Stack Overflow
-
Nl2br - Manual - PHP
-
Strings - Manual - PHP
-
Tính Tổng Các Số Nguyên Từ 0 Tới N Bằng PHP - GokiSoft
-
Tính Tổng Của Các Chữ Số Của Môt Số Nguyên N - Bài Tập PHP - VietTuts
-
Tính Giai Thừa Trong PHP - Bài Tập PHP Có Lời Giải - VietTuts
-
Các Toán Tử Trong PHP
-
Căn Bản PHP - Viblo
-
PHP - Vòng Lặp For Tính Tổng S(n) = 1 + 1/2 + 1/3 + 1/4 +… 1/n
-
Bài 3: Các Kiểu Dữ Liệu Và Phạm Vi Biến Trong PHP
-
How To Create A New Line In PHP - Tutorial Republic
-
\ R Và \ N Có Nghĩa Là Gì Trong PHP? - HelpEx
-
PHP Là Gì?
-
Những Kiến Thức Căn Bản Tổng Quan Về Lập Trình PHP