Smarty questions about the use of truncate
{$d. title|truncate:25}
I would like to let the superfluous title with ... Show
It's just that truncate is like a number, a variety of characters, and Chinese as 1 characters.
But after all, the number accounted for 2 of a Chinese space, and there is the end of the "...", another 3 characters of space.
Causes the headings to be listed after the hierarchy is not aligned.
The number of the display is very short, more Chinese will show very long.
How do you make truncate think that numbers are half a character?
Hope master, veteran advice, thank you!
------Solution--------------------
Why not handle this in PHP? Help Top
------Solution--------------------
Customize functions that intercept Chinese.
------Solution--------------------
Alas, only 20 points.
Save the following code as modifier.mb_truncate.php and put this PHP in the Libs/plugins directory below Smarty
How to use: {$d. title|mb_truncate:25}
PHP Code
function Smarty_modifier_mb_truncate ($string, $length = A, $etc = ' ... ', $charset = ' UTF-8 ', $break _words = False, $mi Ddle = False) { if ($length = = 0) return '; if (Mb_strlen ($string) > $length) { $length-= min ($length, Mb_strlen ($etc)); if (! $break _words &&! $middle) { $string = preg_replace ('/\s+? ( \s+) $/u ', ', Mb_substr ($string, 0, $length +1, $charset)); } if (! $middle) { return mb_substr ($string, 0, $length, $charset). $etc; } else { return mb_substr ($string, 0, $length/2, $charset). $etc. Mb_substr ($string,-$length/2, (Mb_strlen ($string)-$length/2), $charset); } } else { return $string;