hi Yuji.
OK.
I've just understand what you mean.
truncate is just a substr();
substr() can't be used in multibyte language like Japanese.
You should make mbtruncate like this:
class/smarty/plug-ins/modifier.mbtruncate.php
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: modifier
* Name: mbtruncate
* Purpose: Truncate a string to a certain length if necessary,
* optionally splitting in the middle of a word, and
* appending the $etc string.
* -------------------------------------------------------------
*/
function smarty_modifier_mbtruncate($string, $length = 80, $etc = '...',
$break_words = false)
{
if ($length == 0)
return '';
if (strlen($string) > $length) {
$length -= strlen($etc);
if (!$break_words)
$string = preg_replace('/\s+?(\S+)?$/', '', mb_strcut($string, 0, $length+1));
return mb_strcut($string, 0, $length).$etc;
} else
return $string;
}
?>
Of course, mbstring should be installed.
But, both cutting-in-template(mbtruncate) and cutting-in-php might harm EMLH, I think.