The PHP Line break example & code
If you are developing the application to allow the user to enter the values in the text field and then display the same value on the website. If user enters the <enter key> to add the line break in the text field and saves the data. If you the display the same data on html page then it won't be displayed in the different paragraph. Instead all the text will displayed without any line break.
You can use the nl2br() function to add the line break in the text. The nl2br() function adds the <br> tag if it finds the carriage return (\n) in the text. If you text is long and at many places carriage return is present, even then the nl2br() tag will replace all the occurrence of the carriage return with <br> tag.
Here is the syntax of the nl2br() tag:
$myString ="Welcome to the PHP programming.\n\nHere you will learn PHP in detail";
Output generated by the program:
The nl2br() function will add two <br> tags as shown below:
Welcome to the PHP programming.<br /> <br /> Here you will learn PHP in detail
So, now you can use the nl2br() function to add the line break while displaying the data on webpage.
Recommend the tutorial