Home > Article > Backend Development > PHP supports Chinese string splitting function_PHP tutorial
This article shares with you two PHP methods that use the mb_xxx method to achieve Chinese character segmentation. The basic ideas are similar. If necessary Friends can refer to it.
str_split does not support Chinese, use the mb_xx function to implement
?
2 3
4 56 13 14 |
/** * Convert a string to an array * @param string $str * @param number $split_length * @return multitype:string */ function mb_str_split($str,$split_length=1,$charset="UTF-8"){ if(func_num_args()==1){ return preg_split('/(? |
1 2 3 4 5 6 7 8 9 10 | 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; } |