I hope somebody with better problem solving skills can help me out here. I have a textarea and all I had to do is split the text into 50 chars and feed the lines to another app. No problem. But I forgot about line breaks. If someone puts linebreak I have to also make that a seperate line. Here's my current code ($content is the original text). I'm sure there is an easy way I just can't get to it.
$div = strlen($content) / 50;
$x=0;
while ($x<$div) {
$substr=$x*50;
$text = substr($content,$substr,50);
if (trim($text)!="") {
echo $text . "<br>";
}
$x++;
}
Have you looked into PHP's wordwrap
and nl2br
functions?
$result = wordwrap($content, 50, "
"); // first, wrap
$result = nl2br($result); // then, include html breaks
So, this:
$content = <<<EXAMPLE
hope somebody with
better problem solving skills can help me out here.
I have a textarea and all I had to do is split the text into 50 chars and feed the lines to another app.
EXAMPLE;
...yields this:
hope somebody with<br />
better problem solving skills can help me out<br />
here.<br />
<br />
I have a textarea and all I had to do is split<br />
the text into 50 chars and feed the lines to<br />
another app.