mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-09 21:04:28 +02:00
fixed handling of $etc in the truncate modifier when $etc is longer
than $length. thanks to Sylvinus!
This commit is contained in:
2
NEWS
2
NEWS
@@ -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
|
- fix handling of %I with mysql timestamps in the date_format modifier
|
||||||
(Danilo Buerger, boots)
|
(Danilo Buerger, boots)
|
||||||
- update smarty_core_write_file() to better recognize Windows (boots)
|
- update smarty_core_write_file() to better recognize Windows (boots)
|
||||||
|
@@ -31,12 +31,12 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...',
|
|||||||
return '';
|
return '';
|
||||||
|
|
||||||
if (strlen($string) > $length) {
|
if (strlen($string) > $length) {
|
||||||
$length -= strlen($etc);
|
$length -= min($length, strlen($etc));
|
||||||
if (!$break_words && !$middle) {
|
if (!$break_words && !$middle) {
|
||||||
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
|
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
|
||||||
}
|
}
|
||||||
if(!$middle) {
|
if(!$middle) {
|
||||||
return substr($string, 0, $length).$etc;
|
return substr($string, 0, $length) . $etc;
|
||||||
} else {
|
} else {
|
||||||
return substr($string, 0, $length/2) . $etc . substr($string, -$length/2);
|
return substr($string, 0, $length/2) . $etc . substr($string, -$length/2);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user