fixed handling of $etc in the truncate modifier when $etc is longer

than $length.

thanks to Sylvinus!
This commit is contained in:
messju
2007-01-17 22:10:01 +00:00
parent 181dd87df4
commit befdff26d8
2 changed files with 4 additions and 2 deletions

2
NEWS
View File

@@ -1,3 +1,5 @@
- fix handling of $etc in the truncate modifier when $etc is longer
than $length (Sylvinus, messju)
- fix handling of %I with mysql timestamps in the date_format modifier
(Danilo Buerger, boots)
- update smarty_core_write_file() to better recognize Windows (boots)

View File

@@ -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);
}