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

longestdrive's avatar

Inserting Line breaks into Mysql txt

Hi

I have a form with a text area. When a user adds notes they can add new lines as expected whilst they edit.

I want to be able to add new lines to this text in my code but whilst I can add the new text I can't create new lines.

The code to add new text is:

$notes .= date('d/m/Y h:i') . ": Booking created by " . $this->user->present()->fullName() . "<br/ >";

I have also tried \n instead of <br /> but it makes no difference

When I try and display it back in a form text area all I see is the charactersL (<br /> or \n) and no new lines

I have tried:

<textarea>{!! $reservation->notes !!}<textarea/>

    <textarea>{!! e($reservation->notes) !!}<textarea/>

   <textarea>{!! nl2br(e($reservation->notes)) !!}<textarea/>

and same combinations for {{ }}

How can I add text to existing text on a new line so it appears correctly as a new line in the textarea?

0 likes
4 replies
realrandyallen's avatar
Level 44

I used \n and then just simply spat out the value and it worked for me:

<textarea cols="100" rows="100">
    {{ $reservation->notes }}
</textarea>
longestdrive's avatar

Hi @realrandyallen - thank you - been going round in circles on this one!

It works now - the mistake I made when I experimented with \nwas to use single quotes not double - persevered after your comment and tried again with double quotes - phew

Thanks for the great steer

1 like
Cronix's avatar

Be aware that specifically for textareas, if you do

<textarea cols="100" rows="100">
    {{ $reservation->notes }}
</textarea>

instead of

<textarea cols="100" rows="100">{{ $reservation->notes }}</textarea>

you will get extra white space and a line return before your text since everything between the opening and closing <textarea> tag is the value

Please or to participate in this conversation.