note 36594 deleted from function.wordwrap by nlopess
| From: | nlopess@php.net | Date: | Sat, 12 Jun 2004 13:17:35 +0000 |
| Subject: | note 36594 deleted from function.wordwrap by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-70968@lists.php.net to get a copy of this message | ||
Note Submitter: tomasz@codestar.se
----
Discovered that wordwrap doesnt care about "\r\n" that are already there when wrapping so
output can be somewhat strange. Some comments in Swedish, sorry for that ;)
function ww ($sInput, $iW = 100) {
/*
ww 1.0 <tomasz@codestar.se>
Created 2003-10-15
Wordwraps input string considering already existing newlines.
Returns wrapped string with newlines in "\r\n"-format.
$sInput The string to be wrapped
$iW Max number of chars in each row
*/
/* Splitta i delar efter nuvarande radbrytningar i "\r\n"-format */
$aInput = split ("\r\n", $sInput);
/* Splitta i ytterligare delar efter nuvarande "\n"-brytningar */
foreach ( $aInput as $aPiece ) {
$aAdd = split ("\n", $aPiece);
foreach ( $aAdd as $sAddPiece ) {
$aNewInput[] = $sAddPiece;
}
}
$aInput = $aNewInput;
/* Skapa retursträng utifrån alla bitar av insträngen, wrappa varje vit för sig */
foreach ( $aInput as $sPiece ) {
$sO .= wordwrap ($sPiece, $iW, "\r\n") . "\r\n";
}
return $sO;
}