The example of this article describes the PHP custom function to implement the Chinese character segmentation and replacement function. Share it with everyone for your reference, the details are as follows:
header("Content-type:text/html;charset=utf-8"); $str="赵钱孙"; function mbstringToArray($str,$charset) { $strlen=mb_strlen($str); while($strlen){ $array[]=mb_substr($str,0,1,$charset); $str=mb_substr($str,1,$strlen,$charset); $strlen=mb_strlen($str); } return $array; } //用法gbk utf-8 $arr = mbstringToArray($str,"utf-8"); var_dump($arr);
The running results are as follows:
array(3) { [0]=> string(2) "赵" [1]=> string(2) "钱" [2]=> string(2) "孙" }
Hope this article It will be helpful to everyone in PHP programming.
For more relevant articles on PHP using custom functions to implement Chinese character segmentation and replacement, please pay attention to the PHP Chinese website!