mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-02 13:21:36 +01:00
fixed length in modifier.truncate.php
This commit is contained in:
@@ -17,13 +17,11 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...',
|
||||
return '';
|
||||
|
||||
if (strlen($string) > $length) {
|
||||
$length -= strlen($etc);
|
||||
$fragment = substr($string, 0, $length+1);
|
||||
if ($break_words)
|
||||
$fragment = substr($fragment, 0, -1);
|
||||
else
|
||||
$fragment = preg_replace('/\s+(\S+)?$/', '', $fragment);
|
||||
return $fragment.$etc;
|
||||
$length -= strlen($etc);
|
||||
if (!$break_words)
|
||||
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
|
||||
|
||||
return substr($string, 0, $length).$etc;
|
||||
} else
|
||||
return $string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user