The examples in this article describe the ways in which Smarty improved truncate to support Chinese. Share to everyone for your reference, specific as follows:
Smarty's truncate does not support the interception of Chinese. Change the modifier.truncate.php in the plugins in the Smarty directory to the following.
<?php/* Smarty plugin *--------------------------------------------------------- ----* Type:modifier * name:truncate * purpose:truncate A string to a certain length if necessary, * Optionall
Y splitting in the middle of a word, and * appending the $ETC string.
* Update:change substr to Msubstr and add fun msubstr.so it * can bu used in Chinese charset. *-------------------------------------------------------------/function Smarty_modifier_truncate ($string, $
Length = n, $etc = ' ... ', $break _words = False) {if ($length = = 0) return ';
if (strlen ($string) > $length) {$length-= strlen ($ETC); if (! $break _words) $string = Preg_replace ('//s+?
/s+)? $/', ', Substrgb ($string, 0, $length + 1));
Return Substrgb ($string, 0, $length). $etc;
else return $string; function Substrgb ($str, $start, $len) {for ($i =0; $i < $start + $len; $i + +) {$tmpstr = (ord ($str [$i]) >=161 && o RD ($str [$i])<=254&& Ord ($str [$i +1]) >=161 && ord ($str [$i +1]) <=254)? $str [$i]. $str [+ + $i]: $tmpstr = $str [$
I];
if ($i >= $start && $i < ($start + $len)) $tmp. = $tmpstr;
return $tmp; }/* Vim:set expandtab:/*?>
More interested in smarty related content readers can view the site topics: "Smarty Template Primer Tutorial", "PHP Template Technology Summary", "PHP based on PDO Operation Database Skills summary", "PHP Operations and Operator Usage Summary", "PHP Network Programming Skills Summary", " Introduction to PHP Basic Grammar, "Introduction to PHP object-oriented programming", "PHP string (String) Usage Summary", "Php+mysql Database Operations Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on Smarty template.