How To Create A New Line In PHP - Tutorial Republic
Topic: PHP / MySQLPrev|Next
Answer: Use the Newline Characters '\n' or '\r\n'
You can use the PHP newline characters \n or \r\n to create a new line inside the source code. However, if you want the line breaks to be visible in the browser too, you can use the PHP nl2br() function which inserts HTML line breaks before all newlines in a string.
Let's take a look at the following example to understand how it basically works:
Example
Try this code » <?php echo "If you view the page source \r\n you will find a newline in this string."; echo "<br>"; echo nl2br("You will find the \n newlines in this string \r\n on the browser window."); ?>Note: The character \n writes a newline in UNIX while for Windows there is the two character sequence: \r\n. To be on safe side use the \r\n instead.
Related FAQ
Here are some more FAQ related to this topic:
- How to combine two strings in PHP
- How to remove white space from a string in PHP
- How to write comments in PHP
Từ 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
-
PHP Nl2br() Function - W3Schools
-
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
-
\ 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