From fe79c1736b29b853fac266a1b4e8af1c1da15b72 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 9 Jul 2009 16:54:25 -0600 Subject: [PATCH] Add Horde_String::truncate() --- framework/Util/lib/Horde/String.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/framework/Util/lib/Horde/String.php b/framework/Util/lib/Horde/String.php index 61e9606d7..bc60e6959 100644 --- a/framework/Util/lib/Horde/String.php +++ b/framework/Util/lib/Horde/String.php @@ -589,6 +589,21 @@ class Horde_String } /** + * Return a truncated string, suitable for notifications. + * + * @param string $text The original string. + * @param integer $length The maximum length. + * + * @return string The truncated string, if longer than $length. + */ + static public function truncate($text, $length = 100) + { + return (self::length($text) > $length) + ? self::substr($text, 0, 100) . ' ...' + : $text; + } + + /** * Returns true if the every character in the parameter is an alphabetic * character. * -- 2.11.0