Home >php教程 >PHP源码 >PHP中英数字混排字符串的截取

PHP中英数字混排字符串的截取

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-08 17:25:021032browse

因为php是外国开发的,在中英文混合体时截取会经常出现乱码,今天我们要讲了就是来解决这一问的哦,有需要的朋友可以参考一下。

<script>ec(2);</script>
 代码如下 复制代码

function smssubstr($string, $length) {
 if(strlen($string)   return $string; 
 }
 $strcut = '';
 for($i = 0; $i   $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
 }
 return $strcut;
}

for($i=1; $i  ${'smscontent'.$i} = smssubstr($message,$smsper);
 $message = str_replace(${'smscontent'.$i},"",$message);
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn