Home >Backend Development >PHP Tutorial >Regarding the problem of character string segmentation with mixed Chinese and English numbers_PHP tutorial
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;