开发者

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:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa开发者_运维技巧aaaaaaaaaaaaaaaaaaaa

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

How can I do that?

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


Yes, use wordwrap...

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


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>


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

textbox.value = HandleLineBreaks(line, index);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜