【转】正确拆分中英文混合字符串的函数
[*]function arr_split_zh($tempaddtext){
[*] $tempaddtext = iconv("UTF-8", "gb2312", $tempaddtext);
[*] $cind = 0;
[*] $arr_cont=array();
[*]
[*] for($i=0;$i<strlen($tempaddtext);$i++)
[*] {
[*] if(strlen(substr($tempaddtext,$cind,1)) > 0){
[*] if(ord(substr($tempaddtext,$cind,1)) < 0xA1 ){ //如果为英文则取1个字节
[*] array_push($arr_cont,substr($tempaddtext,$cind,1));
[*] $cind++;
[*] }else{
[*] array_push($arr_cont,substr($tempaddtext,$cind,2));
[*] $cind+=2;
[*] }
[*] }
[*] }
[*] foreach ($arr_cont as &$row)
[*] {
[*] $row=iconv("gb2312","UTF-8",$row);
[*] }
[*]
[*]return $arr_cont;
[*]
[*]}
页:
[1]