note 78016 deleted from function.wordwrap by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 18:29:25 +0000 |
| Subject: | note 78016 deleted from function.wordwrap by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155126@lists.php.net to get a copy of this message | ||
Note Submitter: me at NOJUNKPLEASE dot callum-macdonald dot com
----
luismorrison's function will split a string into a first and second line *only*. If your string
is 100 characters long and you wrap at 30 characters you will end up with 30 chars on line 1 and 70
on line 2.
I've included an English translation here for reference as I was going round the bend trying to
figure it out in Spanish! :)
<?php
function splitstroverflow($chain,$length) {
$pri_line = array();
$seg_line = array();
$words = explode(" ",trim($chain));
for ($i = 0; $i < count($words); $i++) {
$sum += strlen($words[$i])+1;
if ($sum >= $length) $seg_line[] = $words[$i] . " ";
else $pri_line[] = $words[$i] . " ";
}
for ($i = 0; $i < count($pri_line); $i++)
$lines[0] .= $pri_line[$i];
for ($i = 0; $i < count($seg_line); $i++)
$lines[1] .= $seg_line[$i];
return $lines;
}
?>