Home  >  Article  >  Backend Development  >  Regarding the problem of character string segmentation with mixed Chinese and English numbers_PHP tutorial

Regarding the problem of character string segmentation with mixed Chinese and English numbers_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:38:12776browse

Because you need to use a text message platform, each text message has a character limit, and the server of the text message platform does not analyze it by itself.

Sigh, the background of the SMS platform will be divided by itself, but the API does not have this function.

I spent some time searching online and found nothing.

Later, I came up with a way, which I think is original.

Just use the interception and replacement function.

The code is as follows:

CODE:

<code style="border: 1px solid rgb(204, 204, 204); margin: 0pt 1em 1em; padding: 0.5em; display: block; font-family: Courier,monospace; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; font-size-adjust: none; font-stretch: normal; line-height: 1.8em;"> <br> function smssubstr($string, $length) {<br> if(strlen($string) <= $length) {<br /> return $string;<br /> }<br /> $strcut = ;<br /> for($i = 0; $i < $length; $i++) {<br /> $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];<br> }<br> return $strcut;<br> }<br> for($i=1; $i<=$smsnum; $i++){<br /> ${smscontent.$i} = smssubstr($message,$smsper);<br /> $message = str_replace(${smscontent.$i},"",$message);<br /> } function smssubstr($string, $length) {

if(strlen($string) <= $length) {

return $string;

} for($i = 0; $i < $length; $i++) { $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i]; } return $strcut; } for($i=1; $i<=$smsnum; $i++){ ${smscontent.$i} = smssubstr($message,$smsper); $message = str_replace(${smscontent.$i},"",$message); } http://www.bkjia.com/PHPjc/486496.html
www.bkjia.com
truehttp: //www.bkjia.com/PHPjc/486496.htmlTechArticleBecause you need to use the SMS platform, each text message has a word limit, and the server of the SMS platform has I don’t know how to analyze myself. Sweat, the background of the SMS platform will be divided by itself, but the API does not have this...
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