In a form that I'm building, I have textareas
which will include a nice amount of text, with line breaks included, such as:
Sentence one
Sentence two
I am posting this to my form by using htmlentities
, ex:
. htmlentities($_POST['textarea']) .
This however, produces the following in the email (HTML email) that gets sent by the form:
Sentence one Sentence two
Is there anyway to preserve line breaks with htmlentities
?
Use nl2br()
which converts \n
to <br />
:
. nl2br(htmlentities($_POST['textarea'])) .
No, it isn't possible. If you want a line break in an HTML document then you have to use either a display: block
(and friends) element, a line break element (<br>
) or a white-space: pre
element.
You can generate <br>
elements using PHP with the nl2br
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With