I'm trying to figure out the best way to split up a body of text (say maybe 400-500 characters long) into 130 character-sized chunks with no words being split. I figured how to do this for the first chunk, but am having problems figuring out how to keep repeating it. Been playing around with this for a while, and came up with the following, but can't seem to figure out why it's not working. Any thoughts?
$inc = -1;
$body_length = 0;
$tmp_chunk = 1;
$tmp_body = '';
$body = '';
$tmp_start = 1;
$final_chunk = 0;
$body = 'On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks. When you create pictures, charts, or diagrams, they also coordinate with your current document look.';
$body_length = length($body);
do
if (($tmp_start + 130) > $body_length) {
$tmp_body = substr($body, $tmp_start, $body_length - $tmp_start);
$final_chunk = 1;}
else {
$tmp_body = substr($body, $tmp_start, 130);}
while (substr(tmp_body, inc, 1) != ' ')
$inc = $inc - 1;
endwhile;
$tmp_body = substr($tmp_body, $tmp_start, 130 + $inc);
$tmp_start = $tmp_start + 130 + $inc;
echo $tmp_body;
$tmp_chunk = $tmp_chunk + 1;
$inc = -1;
$tmp_body = NULL;
while ($final_chunk = 0);