note 10469 deleted from function.wordwrap by jimw

From: Date: Fri, 14 Dec 2001 20:38:09 +0000
Subject: note 10469 deleted from function.wordwrap by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22769@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!

« previous php.notes (#22769) next »