PHP on the string segmentation problem of Chinese and English Numbers mixed row

  • 2020-03-31 20:32:30
  • OfStack

I found some time on the Internet, but I found nothing good.
Then he came up with a way, it is original.
It's just interception and substitution.
 
function smssubstr($string, $length) { 
if(strlen($string) <= $length) { 
return $string; 
} 
$strcut = ''; 
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); 
} 

Related articles: