When users input text into a text area, line breaks are often lost when the text is outputted. To preserve these line breaks, two solutions can be implemented:
The nl2br() function converts newlines (nr) to HTML line breaks (
).
Example:
echo nl2br("This\r\nis\n\ra\nstring\r"); // Output: This<br /> is<br /> a<br /> string<br />
Tags</h3> <p>Wrapping the input in <pre class="brush:php;toolbar:false">tags ensures that the text is displayed exactly as it was entered, including line breaks.
Reference: W3C Wiki - HTML/Elements/pre
The above is the detailed content of How Can I Preserve Line Breaks from a TextArea When Outputting Text?. For more information, please follow other related articles on the PHP Chinese website!