note 10469 added to wordwrap
| From: | gleis at netz-profis dot de | Date: | Fri, 05 Jan 2001 14:39:15 +0000 |
| Subject: | note 10469 added to wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-9406@lists.php.net to get a copy of this message | ||
In addition to the note of john@defected.net (18-Dec-2000 01:08):
This is my version:
function breakString($str, $maxLen, $append = "...") {
return strlen($str) > $maxLen
? rtrim(substr($str, 0, $maxLen-strlen($append))).$append
: $str;
}
Example output:
bS("Hello World", 8) => "Hello..." (maxlen < input length)
bS("Hello World", 9) => "Hello..." (rtrim!)
bS("Hello World", 11) => "Hello World" (boundary)
bS("Hello World", 15) => "Hello World" (input longer)
attention: $maxLen should always be _greater than_ strlen($append). Think of it!
http://www.php.net/manual/function.wordwrap.php