note 78016 added to function.wordwrap
| From: | me at NOJUNKPLEASE dot callum-macdonald dot com | Date: | Mon, 24 Sep 2007 15:52:49 +0000 |
| Subject: | note 78016 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130745@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 194.145.210.3
Probable Submitter: 82.32.140.169
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit -- https://master.php.net/note/edit/78016
Del: integrated -- https://master.php.net/note/delete/78016/integrated
Del: useless -- https://master.php.net/note/delete/78016/useless
Del: bad code -- https://master.php.net/note/delete/78016/bad+code
Del: spam -- https://master.php.net/note/delete/78016/spam
Del: non-english -- https://master.php.net/note/delete/78016/non-english
Del: in docs -- https://master.php.net/note/delete/78016/in+docs
Del: other reasons-- https://master.php.net/note/delete/78016
Reject -- https://master.php.net/note/reject/78016
Search -- https://master.php.net/manage/user-notes.php