Smarty plug-in -- used to replace truncate the truncate of the UTF-8 stuff

Source: Internet
Author: User
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

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.