show value from db to blada textarea

Published 7 months ago by haizone

hi have a textarea in balda and text from the db with

and its show me like that: Helooworldwhat upto me (with br tags)

and i whant to show regular with lines

this is my code:

{!! $review->business_reply !!}

how i can fix that?

i try all: {{ $review->business_reply }} {!! nl2br($review->business_reply) !!} {{ nl2br($review->business_reply) }}

Best Answer (As Selected By haizone)
haizone

@Cronix its didnt work but i found how to fix that:

{!! str_ireplace(["","",""], " ", $review->business_reply) !!}

not to put /r/n i put : &#10 ; (witour the spac)

many thnaks :)

Snapey
Snapey
7 months ago (1,043,395 XP)

use ``` on a line before and after your code so that we can see what you mean

are you trying to display text on the page or within a text area?

Cronix
Cronix
7 months ago (796,540 XP)

you need to convert <br> tags to newlines (\r\n) to display in a textarea.

{!! str_ireplace(["<br />","<br>","<br/>"], "\r\n", $review->business_reply) !!}

I create a helper to do that (autoloaded via composer.json)

function br2nl($text) {
    return str_ireplace(["<br />","<br>","<br/>"], "\r\n", $text);
}

so then just

{!! br2nl($review->business_reply) !!}

Edit: added missing array syntax

haizone

@Snapey I whant to use in the text area Give me exemple how to use what u say

shez1983

first you need to KNOW what the data is stored in the DATABASE as..

and what if you manually add the data in the database as 'Hello this is my name' does this show up in blade as HelloWhatis... or not?

Snapey
Snapey
7 months ago (1,043,395 XP)

please edit your original post as requested

does your text block contain br tags or not?

haizone

@Snapey this is what i get:

http://prntscr.com/ismzsb

and i whant with line after line

Snapey
Snapey
7 months ago (1,043,395 XP)

ok, so read cronix post, above

shez1983

have you tried cronix solution?

haizone

@shez1983 yes i get error: Only variables can be passed by reference

:/

Cronix
Cronix
7 months ago (796,540 XP)

Show your new code.

haizone

@Cronix {!! str_ireplace("", "\r\n", $review->business_reply) !!}

Cronix
Cronix
7 months ago (796,540 XP)

Ah, my apologies, I forgot that it needs to be an array.

{!! str_ireplace(["<br />","<br>","<br/>"], "\r\n", $review->business_reply) !!}
haizone

@Cronix its didnt work but i found how to fix that:

{!! str_ireplace(["","",""], " ", $review->business_reply) !!}

not to put /r/n i put : &#10 ; (witour the spac)

many thnaks :)

Snapey
Snapey
7 months ago (1,043,395 XP)

You're such a genius. Solved your own problem!

Still cannot work out how to paste code in the forum though

haizone

@Snapey Lol tell me how and I do that :)

Please sign in or create an account to participate in this conversation.