Home > php教程 > php手册 > php下关于中英数字混排的字符串分割问题

php下关于中英数字混排的字符串分割问题

WBOY
Release: 2016-06-06 20:33:31
Original
1002 people have browsed it

要用到短信平台的缘故,短信每条又有字数的限制,而短信平台的服务端又不会自己分析。短信平台的后台会自己分割,但api却有没这个功能。

在网上找了一点时间,发现都不怎样。
后来就自己想了个办法,算是原创吧。
只是用截取加替换的功能。
代码如下:
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);
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template