Questions
Tags
I'm using a textarea to enable users to input comments. However, if the users enters new lines, the new lines don't appear when they are outputted. Is there any way to make the line breaks stay.
Any idea how do preserve the line breaks?
This question is related to php mysql html
php
mysql
html
Two solutions for this:
PHP function nl2br():
nl2br()
e.g.,
echo nl2br("This\r\nis\n\ra\nstring\r"); // will output This<br /> is<br /> a<br /> string<br />
Wrap the input in <pre></pre> tags.
<pre></pre>
See: W3C Wiki - HTML/Elements/pre