Mamadou
Mamadou

Reputation: 2307

Outputting correctly a very long textarea value in PHP

I have a textarea with input like this:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

I want an output with line breaks like this:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

How can I do that?

In my previous question, someone suggested wordwrap, which would be useful if the line had spaces.

Upvotes: 0

Views: 117

Answers (3)

gw0
gw0

Reputation: 1593

I don't know if I understand the question correctly, but HTML textarea field also has the wrap attribute (values "soft", "hard", or "off"). Hard wraps the words inside the text box and places line breaks at the end of each line so that when the form is submitted it appears exactly as it does in the text box.

So:

<textarea cols="30" rows="5" wrap="hard">text..</textarea>

Upvotes: 0

Gambrinus
Gambrinus

Reputation: 2136

you could insert a "<br /> at the index, where the break should occur - only for the output.

textbox.value = HandleLineBreaks(line, index);

Upvotes: -1

fire
fire

Reputation: 21531

Yes, use wordwrap...

$text = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
$newtext = wordwrap($text, 10, "<br />", true);
echo $newtext;

Upvotes: 2

Related Questions