mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-15 15:09:51 +01:00
fixed handling of $etc in the truncate modifier when $etc is longer
than $length. thanks to Sylvinus!
This commit is contained in:
@@ -31,12 +31,12 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...',
|
||||
return '';
|
||||
|
||||
if (strlen($string) > $length) {
|
||||
$length -= strlen($etc);
|
||||
$length -= min($length, strlen($etc));
|
||||
if (!$break_words && !$middle) {
|
||||
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
|
||||
}
|
||||
if(!$middle) {
|
||||
return substr($string, 0, $length).$etc;
|
||||
return substr($string, 0, $length) . $etc;
|
||||
} else {
|
||||
return substr($string, 0, $length/2) . $etc . substr($string, -$length/2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user