01-11-2008, 11:06 AM
|
#8 (permalink)
|
|
The Wanderer
Join Date: Jan 2008
Posts: 21
Thanks: 0
|
Here's my effort:
PHP Code:
public static function concat($str, $maxLen = 220, $noHTML = false, $ellipsis = true) { if (self::utf8_strlen($str) > $maxLen) { foreach (explode(' ', $str) as $word) { if ((self::utf8_strlen($out) + self::utf8_strlen($word)) < $maxLen) $out .= "$word ";
else break; }
return self::unicodeTrim($out, ',.-/:;', 'right') . ($ellipsis ? (!$noHTML ? ' <strong>…</strong>' : ' …') : ''); }
else return $str; }
Makes sure words aren't cut in half etc.
It does share the same issue as Will's function; the ellipsis isn't taken into consideration with $maxLen. I personally use the ellipsis symbol instead of 3 full stops.
|
|
|
|