From b01ce468d26d24a3fc1df69f2e473b2fef5075b7 Mon Sep 17 00:00:00 2001 From: messju Date: Wed, 12 Mar 2003 21:56:32 +0000 Subject: [PATCH] fixed length in modifier.truncate.php --- NEWS | 1 + libs/plugins/modifier.truncate.php | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index d1b4a208..d664afdc 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,4 @@ + - fixed length in modifier.truncate.php (messju) - fixed handling of '$'-signs in trimwhitespace outputfilter (messju) - fix bug that makes config files recompile every time (Nagger, Monte) diff --git a/libs/plugins/modifier.truncate.php b/libs/plugins/modifier.truncate.php index 7d10c5ff..72474eba 100644 --- a/libs/plugins/modifier.truncate.php +++ b/libs/plugins/modifier.truncate.php @@ -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; }