X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=functions%2Fstrings.php;h=d00cd835e5bb34e242ab3f55307950dc5b25e53f;hp=c7b6544e76ac9a7e7cddeb35363efc8e157852da;hb=b8ea4ed629e58fb57a4b110867b4e1b84c82610f;hpb=20db5033a7f36d40c7fe11d561069de9c9a2a970 diff --git a/functions/strings.php b/functions/strings.php index c7b6544e..d00cd835 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -27,4 +27,34 @@ return strrev($data); } + // Wraps text at $wrap characters + function wordWrap($passed, $wrap) { + $words = explode(" ", trim($passed)); + $i = 0; + $line_len = strlen($words[$i])+1; + $line = ""; + while ($i < count($words)) { + while ($line_len < $wrap) { + $line = "$line$words[$i] "; + $i++; + $line_len = $line_len + strlen($words[$i])+1; + } + $line_len = strlen($words[$i])+1; + if ($line_len < $wrap) { + if ($i < count($words)) // don't
the last line + $line = "$line
"; + } else { + $endline = $words[$i]; + while ($line_len >= $wrap) { + $bigline = substr($endline, 0, $wrap); + $endline = substr($endline, $wrap, strlen($endline)); + $line_len = strlen($endline); + $line = "$line$bigline
"; + } + $line = "$line$endline
"; + $i++; + } + } + return $line; + } ?>