The smarty template intercepts character strings and garbled characters to solve the problem perfectly

Source: Internet
Author: User
Every time you encounter a problem, you can solve it. When you solve the problem, you will find that you have been making progress ''''

Every time you encounter a problem, you can solve it.

When you solve the problem, you will find that you have been making progress ''''

Soon after learning php, I liked this language. Perfect.

Today, we have encountered a garbled problem. This type of problem should be universally applied to a smarty template loyal person.

I personally think that smarty and php are almost perfect combinations.

The solution is as follows:

The smarty template intercepts several garbled characters behind the string.

Modify the file modifier_truncate.php

Function smarty_modifier_truncatey ($ string, $ length = 80, $ etc = '...', $ count_words = true ){
Mb_internal_encoding ("UTF-8 ");
If ($ length = 0) return '';
If (strlen ($ string) <= $ length) return $ string;
Preg_match_all ("/[x01-x7f] | [xc2-xdf] [x80-xbf] | xe0 [xa0-xbf] [x80-xbf] | [xe1-xef] [x80-xbf] [x80-xbf] | xf0 [x90-xbf] [x80-xbf] [x80-xbf] | [xf1-xf7] [x80-xbf] [x80-xbf] [x80-xbf]/", $ string, $ info );
If ($ count_words ){
$ J = 0;
For ($ I = 0; $ I $ Wordscut. = $ info [0] [$ I];
If (ord ($ info [0] [$ I]) >= 128 ){
$ J = $ j + 2;
} Else {
$ J = $ j + 1;
}
If ($ j >=$ length ){
Return $ wordscut. $ etc;
}
}
Return join ('', $ info [0]);
}
Return join ("", array_slice ($ info [0], 0, $ length). $ etc;
}

Read {$ xnews [t]. title | truncate: 14}

That's simple '''
 

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.