|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
TyroneYeh Smarty n00b
Joined: 30 May 2009 Posts: 1
|
Posted: Sat May 30, 2009 6:15 pm Post subject: plugin truncate function request modify! |
|
|
add mb_substr and mb_strlen can support Unicode char!!!
Thanks
Code: | function smarty_modifier_truncate($string, $length = 80, $etc = '...',
$break_words = false, $middle = 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+)?$/', '', mb_substr($string, 0, $length+1));
}
if(!$middle) {
return mb_substr($string, 0, $length) . $etc;
} else {
return mb_substr($string, 0, $length/2) . $etc . mb_substr($string, -$length/2);
}
} else {
return $string;
}
} |
|
|
Back to top |
|
nothinghood Smarty Rookie
Joined: 20 Aug 2009 Posts: 5
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|