- function ccStrLeft($str,$len) #从左边截取中英文混合字符串
- {
- $ascLen=strlen($str); if($ascLen<=$len) return $str;
- $hasCC=ereg("[xA1-xFE]",$str); #同上
- $hasAsc=ereg("[x01-xA0]",$str);
- if(!$hasCC) return substr($str,0,$len);
- if(!$hasAsc)
- if($len%2 != 0){
- return substr($str,0,$len+$len-2);
- }else{
- return substr($str,0,$len+$len);
- }
- $cind=0;$flag=0;$reallen=0;//实际取字节长
- while($cind<$ascLen && $reallen<$len)
- {
- if(ord(substr($str,$cind,1))<0xA1){ //如果该字节为英文 则加一
- $cind++;
- }else{//否则 加2个字节
- $cind+=2;
- }
- $reallen++;
- }
- return substr($str,0,$cind);
- }
- function SplitContent($content,$smslen){
- $str_tmp=$content;
- $arr_cont=array();
- $len_tmp=0;
- $i=0;//分割绝对位置
- while (strlen($str_tmp)>0){
- $str_tmp=ccStrLeft($str_tmp,$smslen);
- array_push($arr_cont,$str_tmp);
- $i+=strlen($str_tmp);
- $str_tmp=substr($content,$i,strlen($content));
- }
- return $arr_cont;
- }
复制代码 已解决。。。。 |