Updated to Smarty 2.6.26 (June 18th, 2009), we should update to Smarty 3.x (current...
[mirrors/Kyberia-bloodline.git] / wwwroot / smarty / libs / plugins / modifier.truncate.php
index 93c3f510882d7111a915abcffb634f16873ddfbb..35c89690a1556cc6dfa943bde00f40abb43dca15 100644 (file)
@@ -16,6 +16,7 @@
  *           appending the $etc string or inserting $etc into the middle.
  * @link http://smarty.php.net/manual/en/language.modifier.truncate.php
  *          truncate (Smarty online manual)
+ * @author   Monte Ohrt <monte at ohrt dot com>
  * @param string
  * @param integer
  * @param string
@@ -30,12 +31,12 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...',
         return '';
 
     if (strlen($string) > $length) {
-        $length -= strlen($etc);
+        $length -= min($length, strlen($etc));
         if (!$break_words && !$middle) {
             $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
         }
         if(!$middle) {
-            return substr($string, 0, $length).$etc;
+            return substr($string, 0, $length) . $etc;
         } else {
             return substr($string, 0, $length/2) . $etc . substr($string, -$length/2);
         }
This page took 0.133237 seconds and 4 git commands to generate.