Recently, the project is always using truncate to intercept characters, but when the intercept UTF-8 often appears garbled, very annoying,
I decided to use the smarty plug-in to capture characters by myself. I would like to thank Zhu, a student from the PHP community in Anhui ~~
Copy the code in plugins,
My name is modifier. jiequ. php. Don't tell me you don't know how to use it,
If you don't want to write it, you can use Baidu. It's actually very simple.
Post Code
Code <? PHP
/**
* Smarty plugin
Used to intercept the UTF-8 string, instead of truncate
Source: Anhui PHP community http://bbs.hfphp.org
Author: bjk
*/
/**
@ String the string to be intercepted
@ Length the number of characters to be intercepted (). The default length is 80.
@ Etc
*/
Function smarty_modifier_jiequ ($ string, $ length = 80, $ etc = '...')
{
If ($ length = 0)
Return '';
If (mb_strlen ($ string, 'utf-8')> $ length ){
$ String = mb_substr ($ string, 0, $ length, 'utf-8 ');
Return $ string. $ etc;
} Else {
Return $ string;
}
}
?>
Just like truncate ~~~~~~
Article Original: Anhui PHP community http://bbs.hfphp.org/thread-38-1-1.html