XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
modifier.truncate.php
Go to the documentation of this file.
1 <?php
27 function smarty_modifier_truncate($string, $length = 80, $etc = '...',
28  $break_words = false, $middle = false)
29 {
30  if ($length == 0)
31  return '';
32 
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));
37  }
38  if(!$middle) {
39  return substr($string, 0, $length) . $etc;
40  } else {
41  return substr($string, 0, $length/2) . $etc . substr($string, -$length/2);
42  }
43  } else {
44  return $string;
45  }
46 }
47 
48 /* vim: set expandtab: */
49 
50 ?>