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 or inserting $etc into the middle.
17 * @link http://smarty.php.net/manual/en/language.modifier.truncate.php
18 * truncate (Smarty online manual)
26 function smarty_modifier_truncate($string, $length = 80, $etc = '...',
27 $break_words = false, $middle = false)
32 if (strlen($string) > $length) {
33 $length -= strlen($etc);
34 if (!$break_words && !$middle) {
35 $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+
1));
38 return substr($string, 0, $length).$etc;
40 return substr($string, 0, $length/2) . $etc . substr($string, -$length/2);
47 /* vim: set expandtab: */
This page took 0.289808 seconds and 4 git commands to generate.