We have to learn PHP language, and the actual operation, we often encounter the problem does not appear on the books.We only have a good solution to these problems, can truly grasp the knowledge we have learned.In this article, you will learn Chinese characters garbled PHP interception concrete solutions.
PHP interception of Chinese characters without distortion of the relevant code:
function cnSubstr ($ str, $ start, $ len) {$ str_tmp = $ len - $ start; if (strlen ($ str) <$ str_tmp) {$ tmpstr = $ str;} else {$ tmpstr = "";; $ strlen = $ start + $ len; for ($ i = 0; $ i <$ strlen; $ i + +) {if (ord (substr ($ str, $ i, 1))> 0xa0) {$tmpstr .= substr ($ str, $ i, 2); $ i + +;} else {$ tmpstr .= substr ($ str, $ i, 1);}} $ tmpstr .= "..";} return$ tmpstr;}
PHP code above the interception of Chinese characters is no distortion of the specific method, we want to help.