Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kordix's avatar

HTML line break interpretation saved in SQL, from textarea

I want to save line breaks or other html intepretation in my CRUD application, f.e. "Line 1 < br> Line 2" should make a new line or "< b>bold text< /b>"

I also tried special chars like \n &br; They disappear when i write them to sql.

I may try WYSIWYG editor but for my use it would just interpret html.

I suppose solution is easy but I can't find it.

0 likes
6 replies
gorakhyadav's avatar

in blade file tried these following:

{{ $words }}  //No line breaks displayed
{{ nl2br($words )) }} // result as described above
{{ nl2br(e($words)) }} // result as described above```
1 like
nlagdhir's avatar

You should use like this.

{!! nl2br(e($words)) !!}

1 like
kordix's avatar

It is still not it.

It just changes new lines to < br /> But it does not take effect. Instead of new line I just see < br />

Thyrosis's avatar
Thyrosis
Best Answer
Level 17

When it's stored in the DB with the BR-tag, you can then get the text to display properly using {!! $variable !!} instead of {{ $variable }}.

If you use {{}}, Blade will automatically turn all the HTML-tags to safe, displayable codes like & lt; and & gt;.

Using {!! !!} instead, Blade will not convert your HTML tags and the text will display as you intended.

2 likes
kordix's avatar

Daamn thanks, again easy things which I search for hours.

Maybe I'm searching wrong way? I write "blade new line textarea", "blade interpret new line entity inside strings" or "html new line entity Laravel Blade" etc.

BTW do you have a way to interpret other HTML tags like < b >some text </ b>, < i >some text< /i> ?

shoully's avatar

I also searched "save newline in the database" and found this in the seventh result, I also searched for " inside p tag" lol, because I didn't know about "HTML-Tags Safe".

As your question or anyone reading this in the future about , yes it works as expected.

Just to note, if I used {!! !!} and put in the database it will give me newline, but if I used {!! nl2br($words) !!} it will give me double break lines.

Please or to participate in this conversation.