Chinese-supported PHP splits the array code by string length,
Here is the code I wrote to enable the segmentation of Chinese and English mixed characters:
<?phpfunction mbstrsplit ($string, $len =1) { $start = 0; $strlen = Mb_strlen ($string); while ($strlen) { $array [] = Mb_substr ($string, $start, $len, "UTF8"); $string = Mb_substr ($string, $len, $strlen, "UTF8"); $strlen = Mb_strlen ($string); } return $array;} Header (' Content-type:text/html;charset=utf-8 '); $str = ' I love Beijing 3 I love Shanghai-I love Xianggang '; $r = Mbstrsplit ($str, 4); Echo '';p rint_r ($r); Echo '
';? >
Operation Result:
Array ( [0] = = I love beijing [1] = 3 I love [2] = + Sea-I love [3] = Xian [4] = Ggan [5] = g)
<?php function Str_split_unicode ($str, $l = 0) {if ($l > 0) {$ret = Array (), $len = Mb_strlen ($str, "UTF-8"); for ( $i = 0; $i < $len; $i + = $l) {$ret [] = Mb_substr ($str, $i, $l, "UTF-8");} return $ret;} Return Preg_split ("//u", $str,-1, preg_split_no_empty);}? > $s = "not rtret, SSS see GFG not Immortal"; Mild Milk Print_r (Str_split ($s, 5)); Print_r (Str_split_unicode ($s, 5));//Output//array ([0] = [1] = = [2] = SSS [3] = See GF [4] = g [ 5] + RTR [6] = et not [7] = decay)//array ([0] = = Not yet desired s [1] = SS See GF [2] = g no RT [3] = ret Immortal)
The above mentioned is the whole content of this article, I hope you can like.
http://www.bkjia.com/PHPjc/1000258.html www.bkjia.com true http://www.bkjia.com/PHPjc/1000258.html techarticle Support Chinese PHP by string length to split the number of groups of code, the following is the code I wrote, to achieve the split between Chinese and English mixed characters: phpfunction mbstrsplit ($string, $len =1) {...