Added X-out of blank boxes for security.
[openemr.git] / library / plugins / modifier.truncate.php
blob15a26ba9755b2ef6c36580a806c8b4e581958dda
1 <?php
2 /**
3 * Smarty plugin
4 * @package Smarty
5 * @subpackage plugins
6 */
9 /**
10 * Smarty truncate modifier plugin
12 * Type: modifier<br>
13 * Name: truncate<br>
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)
19 * @param string
20 * @param integer
21 * @param string
22 * @param boolean
23 * @return string
25 function smarty_modifier_truncate($string, $length = 80, $etc = '...',
26 $break_words = false)
28 if ($length == 0)
29 return '';
31 if (strlen($string) > $length) {
32 $length -= strlen($etc);
33 if (!$break_words)
34 $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
36 return substr($string, 0, $length).$etc;
37 } else
38 return $string;
41 /* vim: set expandtab: */