Php supports gb2312, uft-8 Chinese and English character truncation function

Source: Internet
Author: User
Php supports gb2312, uft-8 Chinese and English character truncation function. Php Tutorial support gb2312, uft-8 Chinese and English character truncation function? Php intercepts the gb2312 Chinese string functionmysubstr ($ str, $ start, $ len) {$ tmps tutorial tr; $ strlen $ start + $ len; for ($ I php Tutorial supports gb2312, uft-8 Chinese and English character truncation function

 0xa0) {$ tmpstr. = substr ($ str, $ I, 2); $ I ++;} else $ tmpstr. = substr ($ str, $ I, 1);} return $ tmpstr ;}?>
 

Integrate the above two examples

 $ Sublen) return join ('', array_slice ($ t_string [0], $ start, $ sublen )). "... "; return join ('', array_slice ($ t_string [0], $ start, $ sublen);} else {$ start = $ start * 2; $ sublen = $ sublen * 2; $ strlen = strlen ($ string); $ tmpstr = ''; for ($ I = 0; $ I <$ strlen; $ I ++) {if ($ I >=$ start & $ I <($ start + $ sublen) {if (ord (substr ($ string, $ I, 1)> 129) {$ tmpstr. = substr ($ string, $ I, 2);} else {$ tmpstr. = substr ($ str Ing, $ I, 1) ;}} if (ord (substr ($ string, $ I, 1)> 129) $ I ++ ;} if (strlen ($ tmpstr) <$ strlen) $ tmpstr. = "... "; return $ tmpstr ;}}$ str =" string to be intercepted by abcd "; echo cut_str ($ str, 8, 0, 'gb2312');?>


Why? Php // Intercept the gb2312 Chinese string function mysubstr ($ str, $ start, $ len) {$ tmps tutorial tr =; $ strlen = $ start + $ len; for ($ I...

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.