欢迎各位兄弟 发布技术文章
这里的技术是共享的
以下是我编写的代码,实现对中英文混杂字符进行分割: <?php function 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 = '我爱北京3我爱上海-我爱xianggang'; $r = mbStrSplit($str, 4); echo '<pre>'; print_r($r); echo '</pre>'; ?> 运行结果: Array ( [0] => 我爱北京 [1] => 3我爱上 [2] => 海-我爱 [3] => xian [4] => ggan [5] => g )