10 * Smarty truncate modifier plugin
14 * Purpose: Truncate a string to a certain length if necessary,
15 * optionally splitting in the middle of a word, and
16 * appending the $etc string.
17 * @link http://smarty.php.net/manual/en/language.modifier.truncate.php
18 * truncate (Smarty online manual)
25 function smarty_modifier_truncate($string, $length = 80, $etc = '...',
31 if (strlen($string) > $length) {
32 $length -= strlen($etc);
34 $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+
1));
36 return substr($string, 0, $length).$etc;
41 /* vim: set expandtab: */