Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add linebreak to text from Symfony2 Form Textarea

I have a Form with Symfony 2 with a textarea.

If the user writes something like this in the textarea

word1

word2 word3 word4
word5

rest of message

i'm getting the data exactly like this from the form, but without any HTML linebreaks. So if i want to use this text further for sending a email it'll be shown as this

word1 word3 word4 word5 rest of message

How can i save the formatting of the Text? Any suggestions?

like image 805
KhorneHoly Avatar asked Jul 21 '14 12:07

KhorneHoly


2 Answers

If you are wanting to use this in a Twig template then you should use the nl2br filter like..

{{ text|nl2br }} // NOT "bl2br" as I had originally written.
like image 72
qooplmao Avatar answered Sep 24 '22 00:09

qooplmao


You can use nl2br function:

$text = nl2br($text);

echo $text;
like image 45
Steve Avatar answered Sep 24 '22 00:09

Steve