I have a textarea, where the users enters text (with as many returns as they want), and I take that value, insert it into a database, and then update the textarea’s value with the one in the database.
<textarea maxlength="500" cols="110" name="description" rows="15"><?php if(isset($newDesc)) echo snl2br_lose(nl2br($newDesc)); else echo nl2br_lose(nl2br($user->desc));?></textarea>
is my html. The issue i’m having is, whilst submitting the value and inserting it into the database works, it doubles the amount of linebreaks when it fills the value of the textarea.
So if they type
Hey line break
Foobar
it will make the textarea’s value
Hey
line break
line break
Foobar
function nl2br_lose($string) {
return str_replace('<br/>', '
', str_replace('<br />', '
',str_replace('<br>', '
',str_replace('<br >', '
',$string))));
}
is the function i’m using to turn nl2br into textarea “returns”. However, if I take out nl2br_lose from the return, it only has one
, so the issue must be there. I’ve been having trouble with this for the better part of today.
Thanks in advance!
in nl2br_lose:
of course, it exchanges readibility for simplicity. the other option is to write a function to call instead of nl2br: