tags:

views:

59

answers:

1

I have a textarea inside a form. No wrap in the html code is provided. In the php file (forms action=phpfile.php) I get the value of the textarea like so:

$ad_text=wordwrap(nl2br($_POST['annonsera_text']), 47, '<br>', true);
echo $ad_text;

Then the output is:

hellohellohellohellohellohellohellohellohellohe
llohello.
hi.
hi.
hi.

/> hi.
hi.
hi.
hi.

/>

and the original input in the form textarea is like this:

hellohellohellohellohellohellohellohellohellohe
llohello.
hi.
hi.
hi.
hi.
hi.
hi.
hi.

There seem to be a line break after the third \n or so, followed by a '/>'

Any ide why?

Thanks

+3  A: 

wordwrap doesn't view <br> as a linebreak - if you move nl2br after wordwrap it will work as you want, but you should change the wordwrap parameter to "\n" to avoid double-spacing:

$ad_text = nl2br(wordwrap($_POST['annonsera_text'], 47, "\n", true));
Greg
no it doesnt! check your info
Camran
I just tested it and it worked - please supply more info
Greg
Without nl2br, whenever the user hits 'enter' and there is a NL, it gets skipped and is dislayed in a long string!
Camran
Ah, you need to run nl2br *after* wordwrap then
Greg