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)
19 * @author Monte Ohrt <monte at ohrt dot com>
27 function smarty_modifier_truncate($string, $length = 80, $etc = '...',
28 $break_words = false, $middle = false)
33 if (strlen($string) > $length) {
34 $length -= min($length, strlen($etc));
35 if (!$break_words && !$middle) {
36 $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+
1));
39 return substr($string, 0, $length) . $etc;
41 return substr($string, 0, $length/2) . $etc . substr($string, -$length/2);
48 /* vim: set expandtab: */
This page took 2.664472 seconds and 4 git commands to generate.