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...