The article introduces a practical function. If we use php substr to intercept characters, it will be very problematic in Chinese. Today I wrote a better function for intercepting Chinese and English characters. Friends in need can refer to it. .
The code is as follows
代码如下 |
复制代码 |
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);
}
|
| Copy code
|
| 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);
}
Okay, friends in need can take it. I won’t go into details about the principle, just use it.
http://www.bkjia.com/PHPjc/631690.htmlwww.bkjia.com
trueTechArticleThe article introduces a practical function. If we use php substr to intercept characters, it will be very problematic in Chinese. Today I wrote a better function for intercepting Chinese and English characters...
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