My Computer Tips was launched in 2015 and provides information for common tasks in various Linux distributions and other computer related subjects.
My Computer tips has over 290 tutorials and tips.
If you found the information on My Computer Tips useful, please consider sharing our site details.
ID: 58
Category: PHP7
Added: 21st of December 2015
Updated On: Tutorial updated and rechecked on 29th of November 2023
Views: 9,128
If your website allows users to enter information via a textbox, chances are they going to enter new lines as they enter their text. The problem is when you output this information, the line breaks will not be preserved.
To solve this issue in PHP, we can the use the nl2br function. The nl2br() function inserts HTML line breaks (<br />) in front of each newline (n) in a string.
In the example below, we presume that the user has just entered some text via a textbox on your website.
To preserve the line breaks you would use the following php code below.
Linux Forums
Linux Gaming
Other Linux / Computer Sites
Other Sites / Shopping